I have an existing date time string in place
new Date('2014-08-01T00:00:00')
But instead of returning 2014-08-01, it returns as 2014-07-31 in the actually angularJS view.
I wonder is this date time string valid, if not, why its not valid.
Could the T
be the reason that the string return a wrong date?
The console.log return a date of Thu Jul 31 2014 20:00:00 GMT-0400 (EDT)
Thank You
Lets call those -2 are toxic vote downs. They should really recall the days when they are struggling to understand the basic concepts that now apparant to them. Its a shame.
I have an existing date time string in place
new Date('2014-08-01T00:00:00')
But instead of returning 2014-08-01, it returns as 2014-07-31 in the actually angularJS view.
I wonder is this date time string valid, if not, why its not valid.
Could the T
be the reason that the string return a wrong date?
The console.log return a date of Thu Jul 31 2014 20:00:00 GMT-0400 (EDT)
Thank You
Lets call those -2 are toxic vote downs. They should really recall the days when they are struggling to understand the basic concepts that now apparant to them. Its a shame.
Share Improve this question edited Sep 29, 2014 at 16:41 ey dee ey em asked Sep 29, 2014 at 13:33 ey dee ey emey dee ey em 8,66315 gold badges72 silver badges128 bronze badges 4- 2 Your timezone might be messing with the returned result. What is the returned date's time? – Cerbrus Commented Sep 29, 2014 at 13:35
- The displayed date uses your browser timezone. – Florent Commented Sep 29, 2014 at 13:36
- How are you using it in your Angular view? – robertklep Commented Sep 29, 2014 at 13:37
- 1 Do not use the Date constructor to parse strings. That format string (i.e. ISO 8601 without timezone) will be parsed as UTC in most modern browsers, local in Chrome and fail pletely in IE 8 and lower. (BTW, down voters who can't be bothered to explain their actions are plain lazy). – RobG Commented Oct 9, 2014 at 5:28
3 Answers
Reset to default 4At present (Autumn 2014), JavaScript's date/time format diverges from ISO-8601 in a very important way: If there's no timezone indicator on the string, it assumes Z
("Zulu", GMT).
So
new Date('2014-08-01T00:00:00')
...is August 1st at midnight GMT. If you live east of GMT, that will be on the 31st in your local time.
However, this inpatibility with ISO-8601 is being fixed in ES6 and some implementations (including the latest V8 in Chrome) are already updating it. The ES6 spec changes the default to local time; check out §20.3.1.15 ("Date Time String Format", the section number may change) in the draft PDFs or this unofficial HTML version.
The displayed date uses the timezone of your browser/puter. This means that if you are in GMT-1 and you enter 2014-08-01T00:00:00
, the actual date is 2014-08-01T00:00:00 - 1 hour
= 2014-07-31T23:00:00
I have this date in startdate=2021-10-27T00:00:00-04:00, d=new Date(data.StartDate) // outputTue Oct 26 2021 23:00:00 GMT-0500 But date is getting one day before'Tue Oct 26 2021 23:00:00 GMT-0500' in central timezone(below -6,-7,-8...).
Actually I used this it is working fine but for central timezone not working var d = new Date(data.StartDate); console.log(data.startDate); $scope.txtStartDate = ("0" + (d.getMonth() + 1)).slice(-2) + "/" + ("0" + d.getDate()).slice(-2) + "/" + d.getFullYear();