Determine the weekday from a Unix timestamp using AngularJS

I have recently started working with AngularJS and I am trying to extract the weekday from a timestamp obtained from a JSON file located here.

The timestamp can be found in a variable named "dt".

Below is the code snippet where I iterate 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>

The expected output should display the current weekday and the following ten weekdays, like so:

Sun
Mon
Tue
Wed
Thu
Fri
Sat
Sun
Mon
Tue

However, the actual result looks like this:

Sun
Sun
Sun
Mon
Mon
Mon
Mon
Mon
Mon
Mon

Here are the dt values from the array:

1463335200
1463346000
1463356800
1463367600
1463378400
1463389200
1463400000
1463410800
1463421600
1463432400

Any ideas on how to resolve this issue?

Answer №1

This function is working as expected The JSON data contains 10 entries and dates.

Take a look at this code example: https://jsfiddle.net/w33r379e/2/

I used the standard JavaScript date object to interpret your date.

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

Open your console to see the results.

If you are relying on the aforementioned object for your date information, keep in mind that it may not display days as expected because they are not included in the data.

Answer №2

Don't worry about your code, it's working perfectly and accurately reflects your data findings :)

I tested the timestamps using the link provided and confirmed the calculated days are spot on.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

In JavaScript, I aim to decompress a zip file containing binary data by unzipping it

let resourceUrl = "http://localhost:9996/api/GetZipFile?id=1-1" ; $.ajax({ url: resourceUrl, type: 'GET', contentType: 'application/json', success: function (data) { if (data) { // The 'data&apos ...

Ensure that the date range picker consistently shows dates in a sequential order

Currently utilizing the vuetify date range picker component https://i.stack.imgur.com/s5s19.png At this moment, it is showcasing https://i.stack.imgur.com/GgTgP.png I am looking to enforce a specific display format, always showing the lesser date first ...

How can CakePhp's $ajax->link be used to manipulate the result on the complete action?

Recently, I've started working with cakePhp to handle ajax requests using prototype. While my controller is returning the correct value, I'm struggling to figure out how to properly handle it when it comes back looking like this: <?php echo ...

The Increment of DOM Event Detail Stays Unchanged When Angular Click Event is Triggered

Attempting to detect a triple click or touch event in an Angular 7 application. Code snippet from the template: <img id="logoImage" src="/assets/logo.png" (click)="clickLogo($event)"> Code snippet from the component: clickLogo(event) { console ...

Unique Javascript Library Focused on AJAX

Looking for a specific JavaScript library that focuses solely on AJAX functionality, such as a basic XMLHttp wrapper. ...

Forge: Securely encrypting massive files

I rely on the forge framework for implementing PGP functionality, specifically for encrypting large files (2gb or larger) while minimizing RAM usage. What would be the most efficient approach to achieve this? ...

Try employing an alternative angular controller when working with the bootstrap modal

I am trying to implement a bootstrap modal in my main HTML file, and I need some help on how to call another Angular controller for the modal. The button that triggers the modal is within a div that already has an Angular controller, and this is causing th ...

Unable to view iframe's HTML content on Edge and Internet Explorer browsers due to compatibility issues

This code belongs to my Angular application. <div class="with-border" layout="column" flex> <iframe class="no-pointer-events" flex ng-attr-srcdoc="{{vm.campaign.body | toTrustedHTML}}" width="100%" frameborder="0" sandbox="allow-scrip ...

Can you provide some information on AngularPublic.js?

Suppose I decide to include my own unique "provider" in the lineup (within AngularPublic.js), for example: ... $provide.provider({ $anchorScroll: $AnchorScrollProvider, $animate: $AnimateProvider, $browser: $BrowserProvider, $cacheFactor ...

Utilize JavaScript's $.post function to export PHP $_POST data directly into a file

After spending hours trying to figure this out, I've come to the realization that I am a complete beginner with little to no knowledge of what I'm doing... The issue I'm facing is related to some JavaScript code being triggered by a button ...

Reduce the combined character value of the title and excerpt by trimming the excess characters

I am seeking a solution to trim the total character count of a post title and excerpt combined. Currently, I can individually adjust the excerpt through theme settings and the post title using JavaScript. However, due to varying title lengths, the height ...

How can I adjust iframe content to fit properly on a mobile device screen?

I am facing a challenge where I need to embed an iframe into an external website over which I have no control. The only thing I can specify is the size of the iframe on my own website. My goal is to ensure that the content within the iframe adjusts to fit ...

displaying the description of a Wordpress category

How can I display the Wordpress category description and name separately in two different locations? I want to show just the description without including the category name or slug. Currently, I have been using the following code snippet to display only t ...

Tips for looping through an array using forEach and modifying elements in Mongoose

My user model is structured like this: { name: "Some User", events: [{title: "String", count: 1}] } On each application load, I want to iterate over all arrays and perform some calculations. In the example below, I'm attempting to update the count ...

What is the process for cancelling a jQuery 3.0 AJAX request?

What is the best way to cancel an AJAX request in jQuery 3.0? this.request = $.ajax(); The newer version of jQuery does not support the abort method in promises. if(this.request && this.request.state() == 'pending') { this.request.abort(); & ...

Preserving the most recent choice made in a dropdown menu

Just started with angular and facing an issue saving the select option tag - the language is saved successfully, but the select option always displays English by default even if I select Arabic. The page refreshes and goes back to English. Any assistance o ...

Obtaining an image from a URL, saving it, and then animating it? That definitely

Looking to create a dynamic animation with images that update every 15 minutes from the following URL: How should I go about storing and looping through the most recent 24 images for the animation? Is using a MySQL database the best option or are there o ...

Leveraging data stored in a parent component within a child component in Vue.js

Working with Laravel Spark, I have implemented a component within another component. <parent-component :user="user"> <child-component :user="user" :questions="questions"></child-component> <parent-component> Inside the parent ...

Iterate through nested objects in Javascript

I am having trouble extracting only the word from each new instance of the newEntry object. It shows up in the console every time I add a new word, but not when I assign it to .innerHTML. Can someone assist me with this issue? Full code: <style ty ...

Having issues with loading THREE.js object within a Vue component

I'm baffled by the interaction between vue and THREE.js. I have the same object that works fine in a plain JS environment but not in vue.js. The canvas remains empty in vue.js and the developer console displays multiple warnings. The code I used in J ...