0

Printing a date like:

{{current.sys.sunrise | date:date}}

Problem is it is being stored in the database as for example: 1476873429. Believe it is milliseconds from 1970. The output is something like: Jan 18, 1970.

Is some kind of custom filter required to format it to current time?

0

2 Answers 2

2

You should multiply your timestamps by 1000, you're storing seconds but JavaScript Dates take milliseconds as arguments :

console.log(new Date(1476873429)) // outputs Sun Jan 18 1970
console.log(new Date(1476873429 * 1000)) // outputs Wed Oct 19 2016
Sign up to request clarification or add additional context in comments.

Comments

0

You can try like this :

$filter('date')(date, format, timezone)

i.e

 <span ng-non-bindable>{{1288323623006 | date:'medium'}}</span>:
    <span>{{1288323623006 | date:'medium'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span>:
   <span>{{1288323623006 | date:'yyyy-MM-dd HH:mm:ss Z'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:'MM/dd/yyyy @ h:mma'}}</span>:
   <span>{{'1288323623006' | date:'MM/dd/yyyy @ h:mma'}}</span><br>
<span ng-non-bindable>{{1288323623006 | date:"MM/dd/yyyy 'at' h:mma"}}</span>:
   <span>{{'1288323623006' | date:"MM/dd/yyyy 'at' h:mma"}}</span><br>

1 Comment

any idea on how to get the date to $filter when it is in $scope.current.sys.sunrise?

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.