Date Filter Localization

3,108 views
Skip to first unread message

Joshua Miller

unread,
Jan 6, 2013, 4:24:34 PM1/6/13
to angular
Hello!

When using the date filter, the date string and object I provide seem to be treated by default as UTC, so when I use the filter, it localizes the date, which becomes eight hours off (PST). If I provide an 'T' offset to the filter, all works fine. 


What am I doing incorrectly?

Josh

Pawel Kozlowski

unread,
Jan 6, 2013, 4:47:11 PM1/6/13
to ang...@googlegroups.com
Hi Josh!

My understanding is that:

1) JavaScript interprets dates in a local time-zone
2) Date filter is interpreting dates in UTC if no time-zone is
specified. Otherwise it uses a specified time-zone (Tx).

So this is a bit of discrepancy...
Do you expect to have Date filter interpret time in the local time-zone?

Somehow related: https://github.com/angular/angular.js/issues/847

Cheers,
Pawel
> --
> You received this message because you are subscribed to the Google Groups
> "AngularJS" group.
> To post to this group, send email to ang...@googlegroups.com.
> To unsubscribe from this group, send email to
> angular+u...@googlegroups.com.
> Visit this group at http://groups.google.com/group/angular?hl=en-US.
>
>



--
Question? Send a fiddle
(http://jsfiddle.net/pkozlowski_opensource/Q2NpJ/) or a plunk
(http://plnkr.co/)
Need help with jsFiddle? Check this:
http://pkozlowskios.wordpress.com/2012/08/12/using-jsfiddle-with-angularjs/

Looking for UI widget library for AngularJS? Here you go:
http://angular-ui.github.com/

Ivo Reis

unread,
Jan 6, 2013, 4:52:55 PM1/6/13
to ang...@googlegroups.com
Hey Joshua, 

Here the example works fine, maybe because my time is UTC. The only difference i found was on the second example  new Date(2013, 01, 01); but maybe it's because the month, in this format, should start at 0 (January)

Joshua Miller

unread,
Jan 6, 2013, 5:36:10 PM1/6/13
to angular
Hello! Thanks for responding.

@Ivo - you are right about the second one. That was my mistake.

@Pawel - The localization performed by the filter is a big value. But my expectation for it is that it would be uniform in its handling of dates. If Javascript localizes the date when creating a Date object (which it arguably should), then my assumption was that the filter would do the same.

But after further thought, I realize this is tricky territory; if a date is coming from the server (as most probably are) then the app cannot assume that a local timezone applies. That said, if a server is storing dates, then it really _should_ be stored with a timezone anyway.

I can see both sides of this, but my personal preference would be to assume local time (rather than UTC) when none is specified. This would make the filter consistent in its output when handling strings and Date objects - and make the most sense for the "best practice" cases for client- and server-generated date strings.

Thoughts?

Josh


--

Sandip Bhavsar

unread,
Jan 28, 2013, 5:25:16 AM1/28/13
to ang...@googlegroups.com
Hello All,

I have issue with displaying time using datefilter.

Below is scenario :

When I pass "2013-01-28T15:20:02.577" to datefilter : "{{date2 | date:'yyyy-MM-dd HH:mm:ss Z'}}". It converts to "2013-01-28 20:50:02 -5.530"

I had pass "15:20:02" time and it converts to "20:50:02" . I need same time as I have passed.

Please help.

Abdul Gaffar

unread,
Aug 27, 2014, 3:05:21 AM8/27/14
to ang...@googlegroups.com
I am too facing same problem as mentioned by Sandip Bhavsar... :(

amit jain

unread,
Apr 23, 2015, 6:24:13 AM4/23/15
to ang...@googlegroups.com
use timezone {{ item.date | date : format : timezone}} like utc
Reply all
Reply to author
Forward
0 new messages