angular-datetime icon indicating copy to clipboard operation
angular-datetime copied to clipboard

UK Date Format

Open Neilski opened this issue 11 years ago • 3 comments

I have a simple date only field using the UK data format dd/MM/yyyy as follows:

<input id="startDate" type="text" name="startDate" datetime="dd/MM/yyyy" ng-model="startDate" required />

If I then add a bound value to the page:

<p>Date: {{ startDate }}</p>

and set the input to '19/5/2015' the reflected value changes to '2015-05-18T23:00:00.000Z' which is one hour behind where I would have expected it to be.

I am not sure if this issue is related to daylight savings (we are currently running British Summer Time GMT+1)?

Neilski avatar May 28 '15 14:05 Neilski

'2015-05-18T23:00:00.000Z' is in ISO format.

The timezone is always zero UTC offset, as denoted by the suffix "Z"

To get locale time, try:

<p>Date: {{ startDate.toLocaleString() }}</p>

or use the date filter in Angular:

<p>Date: {{ startDate | date:'fullDate' }}</p>

eight04 avatar May 28 '15 16:05 eight04

Thank you for the explanation, but I am still slightly confused... The date in question is being supplied from an HTTP GET request from the server. The date supplied by the server is '2015-05-15T00:00:00' and it is this date that initially gets bound and displayed in the view, in my case 15/5/2015. When the data gets POSTed back it gets changed to '2015-05-14T23:00:00Z' i.e. the displayed date -1 hour. It is this conversion from displayed date to bound date that is confusing me. In this scenario, is it expected that the server should always store the date with a zero UTC offset and then convert to to locale time to service the request or store in local time and convert the response?

Sorry, I suspect this is a more general question than it should be.

Neilski avatar May 28 '15 16:05 Neilski

Please ignore my last message. It seems that AngularJS's $http.post() method is responsible from the conversion from local date (UTC+ 1) to UTC+0. I will investigate further - thank you for your help.

Neilski avatar May 28 '15 20:05 Neilski