[英]retrieving day from the given date in string in javascript
I have this date in this format.我有这种格式的日期。
var str="2019-08-19";(year/month/date)
var parts =str.split('-');
var day =parseInt(parts[2],10);
I need to figure out as which day was 19th (Monday/Tuesday /...) .我需要弄清楚哪一天是 19 号 (Monday/Tuesday /...) 。 What i tried doing was splitting the given date but that could only give the information such as 19 etc
我尝试做的是拆分给定的日期,但这只能提供诸如 19 等信息
You can simply do this你可以简单地做到这一点
var d = new Date( "2019-08-19");
var weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var n = weekday[d.getDay()];
Following example will help you.下面的例子会对你有所帮助。
var days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
var d = new Date("2019-08-18");
var dayName = days[d.getDay()];
document.getElementById("myId").innerHTML = dayName;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.