<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>判断当前是时间是否在设定时间之前</title> </head> <body> <script type="text/javascript"> (function(){ var currentDate = new Date(); var year = currentDate.getFullYear();//年 var month = currentDate.getMonth()+1;//月 var day = currentDate.getDate();//日 var hour = currentDate.getHours();//时 var minute = currentDate.getMinutes();//分 var second = currentDate.getSeconds();//秒 var millisecond = currentDate.getMilliseconds();//毫秒 console.log("currentDate:"+currentDate); console.log("年:"+year+" 月:"+month+" 日:"+day+" 时:"+hour+" 分:"+minute+" 秒:"+second+" 毫秒:"+millisecond); console.log(""+year+month+day+hour); if(year>2018){ expired() }else if(month>9){ expired() }else if(month==9&&day>24){ expired() } function expired(){ console.log('该时间在设定时间之后,已过期'); return false; } })() </script> </body> </html>