<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>date对象设置set</title> </head> <body> <script> var today=new Date(); var weeks=["日","一","二","三","四","五","六"]; //today.setFullYear(2222);//设置年份为2222 //document.write(today.getFullYear()+"<br />");//2222 //today.setMonth(13);//设置月份为13 //document.write(today.getMonth()+"<br />");//1,月份超过12后会自动进入下一年 //document.write(today.getFullYear()+"<br />");//2223,因上面设置的月份为13,而增加1年 //获取明年的今天是星期几 //today.setFullYear(today.getFullYear()+1);//将今天获取的年份+1 //document.write(weeks[today.getDay()]);//输出年份+1后的时间 //获取其他时间 var year=today.getFullYear(); var month=today.getMonth()+1; var date=today.getDate(); //时,分,秒…………省略 var tim=new Date(year-1,month,date+50);//去年:今年-1;50天后:今天+50; document.write("去年的今天50天后是:"+tim.getFullYear()+"年"+tim.getMonth()+"月"+tim.getDate()+"日 星期"+weeks[tim.getDay()]); </script> </body> </html>