1. let time=new Date().toLocaleString('chinese',{hour12:false});
    1. var now = new Date();
    2. var year = now.getFullYear(); //得到年份
    3. var month = now.getMonth(); //得到月份
    4. var date = now.getDate(); //得到日期
    5. var day = now.getDay(); //得到周几
    6. var hour = now.getHours(); //得到小时
    7. var minu = now.getMinutes(); //得到分钟
    8. var sec = now.getSeconds(); //得到秒
    9. month = month + 1;
    10. if (month < 10) month = "0" + month;
    11. if (date < 10) date = "0" + date;
    12. if (hour < 10) hour = "0" + hour;
    13. if (minu < 10) minu = "0" + minu;
    14. if (sec < 10) sec = "0" + sec;
    15. var time = "";
    16. time = year + "-" + month + "-" + date + " " + hour + ":" + minu + ":" + sec;
    1. <script type="text/javascript">
    2. function addDay(datetime, days) {
    3. var old_time = new Date(datetime.replace(/-/g, "/")); //替换字符,js不认2013-01- 31,只认2013/01/31
    4. var fd = new Date(old_time.valueOf() + days * 24 * 60 * 60 * 1000); //日期加上指 定的天数
    5. var new_time = fd.getFullYear() + "-";
    6. var month = fd.getMonth() + 1;
    7. if (month >= 10) {
    8. new_time += month + "-";
    9. } else {
    10. //在小于10的月份上补0
    11. new_time += "0" + month + "-";
    12. }
    13. if (fd.getDate() >= 10) {
    14. new_time += fd.getDate();
    15. } else {
    16. //在小于10的日期上补0
    17. new_time += "0" + fd.getDate();
    18. }
    19. return new_time; //输出格式:2013-01-02
    20. }
    21. alert(addDay("2013-11-12", 1)); //弹出值:2013-11-13
    22. </script>
    1. var startDate1 ='2012-12-30 00:00:00' ;
    2. let start1 = new Date(startDate1.replace(/\-/g, "\/"));
    3. var startDate2 ='2012-12-30 13:13:02' ;
    4. let start2 = new Date(startDate2.replace(/\-/g, "\/"));
    5. start2 .getTime();// 获取时间戳 单位毫秒
    6. console.log(start1,start1<start2) // Sun Dec 30 2012 00:00:00 GMT+0800 (中国标准时间) true
    1. var theTime = params.row.alarmDuration; // 秒
    2. var middle = 0; // 分
    3. var hour = 0; // 小时
    4. //parseInt() 函数可解析一个字符串,并返回一个整数
    5. if (theTime > 60) {
    6. middle = parseInt(theTime / 60);
    7. theTime = parseInt(theTime % 60);
    8. if (middle > 60) {
    9. hour = parseInt(middle / 60);
    10. middle = parseInt(middle % 60);
    11. }
    12. }
    13. var result = "" + parseInt(theTime) + "秒";
    14. if (middle > 0) {
    15. result = "" + parseInt(middle) + "分" + result;
    16. }
    17. if (hour > 0) {
    18. result = "" + parseInt(hour) + "小时" + result;
    19. }
    20. return h("span", result);