Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make AngularJS simply print the date without applying a time zone ?

I return from WEBapi a date like

2013-01-01T00:00:00

And I want

  {{msa.StartDate | date:'yyyy-MM'}} 

To be

2013-01

But because it wants to take my current time zone in consideration (US eastern) it is

2012-12

Is there a easy way to tell it DO NOT CARE ABOUT TIMEZONES? Or is there some other filter I can run the date through to ignore my time zone?

like image 296
punkouter Avatar asked Dec 30 '13 19:12

punkouter


2 Answers

As it is described in documentation "If no timezone is specified in the string input, the time is considered to be in the local timezone." (http://docs.angularjs.org/api/ng.filter:date). So you can set time zone yourself. For example this will use UTC time zone

{{'2013-01-01T00:00:00' + 'Z' | date:'yyyy-MM-dd HH:mm'}}

Result (I'm on the West Coast and have 8 hours difference with London)

2012-12-31 16:00

like image 93
webdev Avatar answered Oct 06 '22 10:10

webdev


As of at least Angular 1.4 you can use the date filter's "timezone" parameter to format the date for a given offset. In this case, to keep the time unchanged, use "UTC".

{{msa.StartDate | date:'yyyy-MM':'UTC'}}
like image 36
Nate Whittaker Avatar answered Oct 06 '22 12:10

Nate Whittaker