Tuesday, 15 January 2013

javascript - Angular JS - Date changes when submitting to $http - Timezone issue -



javascript - Angular JS - Date changes when submitting to $http - Timezone issue -

i having unusual problem date changes when passed api through $http.put, suspect timezone issue:

datepicker triggers ng-change event - console.log:

tue jun 10 2014 00:00:00 gmt+0100 (gmt summer time)

passed api using angular $http.put...

when hits fiddler:

startdate=2014-06-09t23:00:00.000z

as can see date changes 10th june 9th june.

how can stop alter of date? timezone causing change? both api , client side running on localhost.

further this:

when field clicked sec time , datepicker launched / date selected, sec time problem not appear:

console.log:

wed aug 06 2014 22:00:00 gmt+0100 (gmt summer time)

fiddler info received:

startdate=2014-08-06t21:00:00.000z

i think tz issue, b/c difference between gmt+0100 , startdate=2014-06-09t23:00:00.000z 5 hours.

.

the issue:

your local time bst (british summer time) equivalent gmt +1

this going default time when create api call.

however, api written google in california, , rather egocentric. therefore, they're automatically converting time since you're not providing date formatting "instructions".

in other words, chrome conversion nicely when print console.log(), when create $http.put, angular, without explicit formatting you, makes phone call using it's default tz (which pst)

.

resolution

you need forcefulness date formatting locale.

angular template

{{ date_expression | date : 'yyyy-mm-dd hh:mm:ss'}}

in javascript

$filter('date')(date, 'yyyy-mm-dd hh:mm:ss')

using localization

<html> <head> <title>my angular page</title> <script src="angular-locale_en-uk.js"></script> ... </head> <body> ... </body> </html>

javascript angularjs date-format angular-ui-bootstrap timezoneoffset

No comments:

Post a Comment