1、时间格式化
1 //昨天的时间
2 var day1 = new Date(); 3 day1.setTime(day1.getTime()-24*60*60*1000);
4 var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();
5 //今天的时间
6 var day2 = new Date(); 7 day2.setTime(day2.getTime());
8 var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();
9 //明天的时间
10 var day3 = new Date();
11 day3.setTime(day3.getTime()+24*60*60*1000);
12 var s3 = day3.getFullYear()+"-" + (day3.getMonth()+1) + "-" + day3.getDate();
13 //拼接时间
14 function show(){
15 var str = "" + s1 + "至" + s2;
16 return str;
17 }
18 //赋值doubleDate
19 $('#dateS').val(show());</pre>
2、下面是具体到时分秒的获取方法
1 function writeCurrentDate() {
2 var now = new Date();
3 var year = now.getFullYea