JS日期相关代码
- UTC时间转换为标准时间
//UTC时间转换为标准时间 function Todate(num) { num = num + ""; var date = ""; var month = new Array(); month["Jan"] = 1; month["Feb"] = 2; month["Mar"] = 3; month["Apr"] = 4; month["May"] = 5; month["Jan"] = 6; month["Jul"] = 7; month["Aug"] = 8; month["Sep"] = 9; month["Oct"] = 10; month["Nov"] = 11; month["Dec"] = 12; var week = new Array(); week["Mon"] = "一"; week["Tue"] = "二"; week["Wed"] = "三"; week["Thu"] = "四"; week["Fri"] = "五"; week["Sat"] = "六"; week["Sun"] = "日"; str = num.split(" "); date = str[5] + "-"; //str[3] 时间 date = date + month[str[1]] + "-" + str[2] + " " + str[3]; return date; }
- 123
- 日期对象也可用于比较两个日期。
var d=new Date();
d.setFullYear(2008,7,9);
//表示月份的参数介于 0 到 11 之间。也就是说,如果希望把月设置为 8 月,则参数应该是 7。
var myDate=new Date()
myDate.setDate
(myDate.getDate()+5)