Home  >  Article  >  Web Front-end  >  js to get the current time (including today, tomorrow and yesterday)

js to get the current time (including today, tomorrow and yesterday)

炎欲天舞
炎欲天舞Original
2017-08-04 16:00:312916browse

//昨天的时间
var day1 = new Date();
day1.setTime(day1.getTime()-24*60*60*1000);
var s1 = day1.getFullYear()+"-" + (day1.getMonth()+1) + "-" + day1.getDate();
//今天的时间
var day2 = new Date();
day2.setTime(day2.getTime());
var s2 = day2.getFullYear()+"-" + (day2.getMonth()+1) + "-" + day2.getDate();
//明天的时间
var day3 = new Date();
day3.setTime(day3.getTime()+24*60*60*1000);
var s3 = day3.getFullYear()+"-" + (day3.getMonth()+1) + "-" + day3.getDate();
//拼接时间
function show(){
  var str = "" + s1 + "至" + s2;
  return str;
}
//赋值doubleDate
 $('#dateS').val(show());

The above is the detailed content of js to get the current time (including today, tomorrow and yesterday). For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn