Get exact day from date string in Javascript

﹥>﹥吖頭↗ 提交于 2019-12-05 13:07:05

To get the day of the month use getDate():

var final_date = myDate.getDate()+"-"+(myDate.getMonth()+1)+"-"+myDate.getFullYear();

W3 schools suggests just building your days of the week array and using it:

var d=new Date();
var weekday=new Array(7);
weekday[0]="Sunday";
weekday[1]="Monday";
weekday[2]="Tuesday";
weekday[3]="Wednesday";
weekday[4]="Thursday";
weekday[5]="Friday";
weekday[6]="Saturday";

var n = weekday[d.getDay()];

Not super elegant, but usable.

var dateString = 'Mon Jun 24 2013 05:30:00 GMT+0530 (India Standard Time)';
var myDate = new Date(dateString);
var final_date = myDate.getDate()+"-"+(myDate.getMonth()+1)+"-"+myDate.getFullYear();

Replace getDay() with getDate().

The above will return the local date for each date part, use the UTC variants if you need the universal time.

powercoder23

I think you will have to take an Array of the days & utilize it using the received index from the getDay() method.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!