How do I get the day of the week from a timestamp in JavaScript? I'd like to get this from a timestamp I specify, not the current date.
Thanks
The getDay() method returns the day of the week (0 to 6) of a date.
To get the day, month and year values from a timestamp: You can pass a timestamp (in milliseconds) to the Date() constructor to create a Date object. We used the following 3 date-related methods: Date. getFullYear method - returns a four-digit number representing the year that corresponds to a date.
Translate the Date(). getDay() to a string day name : getDay « Date « JavaScript Tutorial. The getDay() method returns the day of the week expressed as an integer from 0 (Sunday) to 6 (Saturday). 12.6.
var timestamp = 1400000000;
var a = new Date(timestamp*1000);
var days = ['Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday'];
var dayOfWeek = days[a.getDay()]
Now the "day of the week" is in the dayOfWeek variable.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With