Shiv Kumar Ganesh
Shiv Kumar Ganesh

Reputation: 3825

DateTime Filter AngularJS not Giving Correct Date?

I am using backend as Tomcat which gives me timestamp as follows :-

1448966450000 If I use the website to convert this time to datetime it gives me something like below :-

1448966450000 -> Wed, 02 Dec 47885 00:33:20 GMT

But when I use a Filter for AngularJS it gives me something like this:-

{{1448966450000 | date: "MMM dd,yyyy '@' hh:mma"}} -> Dec 01,2015 @ 04:10PM

I am living at India and according to IST the time which I receive with the filter is pretty wrong. I am not able to understand where the problem lies.

NOTE: Date Shown by angular is wrong while the former one is the correct one.

Upvotes: 1

Views: 470

Answers (2)

aeryaguzov
aeryaguzov

Reputation: 1163

  1. Take a look at your timestamp, your site needs timestamp in seconds, but angular filter accepts milliseconds, so you need to multiply your timestamp in filter on 1000, you need to enter 1448966450000000, not 1448966450000

  2. Check the timezone: add timezone to output format (Z)

  3. If timezone is not suitable for you, set preferred timezone

    {{1448966450000 | date: "MMM dd,yyyy '@' hh:mma" : '+0530'}}

For more information see https://docs.angularjs.org/api/ng/filter/date

Upvotes: 1

Guenter Guckelsberger
Guenter Guckelsberger

Reputation: 940

The timestamp you are using is in milliseconds since 1/1/1970 The angular filter does it right. The website you test it wants the timestamp in seconds.

Upvotes: 0

Related Questions