Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting day of the week from timestamp using JavaScript

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

like image 649
Pidoaisn Avatar asked Apr 12 '11 11:04

Pidoaisn


People also ask

How do I get the day of the week in JavaScript?

The getDay() method returns the day of the week (0 to 6) of a date.

How do you get a day time stamp?

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.

How do you get day from string?

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.


1 Answers

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.

like image 92
klidifia Avatar answered Oct 18 '22 22:10

klidifia