I thought I had a standard ISO date and the Javascript Date() function should convert it with no parsing,
To convert a string to a Date, it must be parsed, you can't avoid that.
but I get the following:
my date :
2015-12-08T13:42
Javascript date function result:
Tue Nov 12 2075 13:42:00 GMT+0100
Is my date in an incorrect format or have I misunderstood the Data
function?
Apart from the year, that is the expected result. From ES5, ISO 8601 format date strings are parsed by the Date constructor (and Date.parse, they are equivalent for parsing).
A plain date string (e.g. 2015-12-08) should be parsed as UTC. A date and time should be parsed as either local if no timezone is provided, or using the provided timezone.
The string "2015-12-08T13:42" does not have a timezone, so it will be parsed using the host timezone settings to produce a date that is equivalent to a local date and time of 8 December, 2015 at 1:42 pm. So it will represent a different moment in time in each time zone with a different offset.
Parsing of strings with the Date constructor is strongly discouraged as it is largely implementation dependent, either write a simple function or use a library. You don't say whether you want the string parsed as local or UTC, a simple function to parse it as UTC is:
// 2015-12-08T13:42
function parseISOAsUTC(s) {
var b = s.split(/\D/);
return new Date(Date.UTC(b[0], --b[1], b[2], b[3], b[4], b[5]||0));
}
var d = parseISOAsUTC('2015-12-08T13:42');
console.log('Local: ' + d.toLocaleString() +
'\nUTC: ' + d.toISOString());
You should add some validation to deal with out of bounds values.