user1885868 user1885868 - 6 months ago 19
Javascript Question

Get Weekday from timestamp using AngularJS

I am new to AngularJS and I would like to extract the weekday from a timestamp I am getting from a JSON file located here.

The timestamp is located in a variable called

"dt"
.

This is the code part where I run through the JSON file using AngularJS :

<div class="row" ng-repeat="t in weather.list">
<div class="date">
{{t.dt*1000 | date:'EEE'}}
</div>
</div>


It is supposed to return the current weekday as well as the next ten weekdays, something like this :

Sun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
Tue


But this is what I get :

Sun
Sun
Sun
Mon
Mon
Mon
Mon
Mon
Mon
Mon


How can I fix this ?

Thanks !

Answer

This behaves correctly Your json has 10 entries and 10 dates.

Check this fiddle: https://jsfiddle.net/w33r379e/2/

I user normal JavaScript date object to parse your date.

const date = new Date(entry.dt*1000);

open your console and look at the results.

If you are using the above object as your date source you wont get the days like you expect because they are simply not there.

Comments