尝试从用户输入的出生日期创建日期对象,然后从他们输入的日期开始获取日期:
MONTHS = 'JANFEBMARAPRMAYJUNJULAUGSEPOCTNOVDEC'; //months
var dateString = prompt('Enter your birth date in the form dd mmm yyyy','26 APR 1988'); //get users date of birth
var substrings = dateString.split(' ');
var day = substrings[0];
var month = substrings[1];
var year = substrings[2];
var pos = MONTHS.indexOf(MONTHS);
if (pos >= 0) {
}
alert(MONTHS.indexOf(month)/3);
var daysOfWeek = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"];
var daysOfWeek = new Date('day','month','year');
document.writeln(daysOfWeek.getDay());{
我不确定在新的约会对象中放什么,我尝试过一些东西,我完全偏离了轨道吗?
答案 0 :(得分:0)
Date
构造函数的语法略有不同。请尝试以下方法:
var MONTHS = ["JAN", "FEB", ..., "DEC"];
var monthNum = MONTHS.indexOf(month);
var birthDate = new Date(year, monthNum, day);
请注意monthNum
为零索引(即0 = 1月,1 = 2月,...,11 = 12月)。