1

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.

2 Answers 2

1
  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

Sign up to request clarification or add additional context in comments.

2 Comments

I am still not getting the date as mentioned in the former case. Have a look at this fiddle. jsfiddle.net/69o08c02/3
jsfiddle.net/69o08c02/4 - timezone conversion works, but take a look at your timestamp - it uses milliseconds. I'll edit an answer
0

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.

2 Comments

Actually thats not the case. You can find the conversion is the correct date while the angular one is wrong. Sorry I would update the same.
Angular expressions are a subset of javascript plus the pipe operator. In your filter expression, 144896645000 is interpreted as the time since 1/1/1970 in milliseconds. This is the javascript default. Not, as you expect, as a unix timestamp. Sorry, but angular does it right.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.