WeChat applet obtains system time, timestamp, time stamp addition and subtraction

Read the article and scan to get the red envelope.

http://blog.csdn.net/ufo00001/article/details/72834437

//get current timestamp
    var timestamp = Date.parse(new Date());
    timestamp = timestamp / 1000;
    console.log("The current timestamp is: " + timestamp);

//get current time
    var n = timestamp * 1000;
    var date = new Date(n);
    //year
    var Y = date.getFullYear();
    //moon
    var M = (date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
    //day
    var D = date.getDate() < 10 ? '0' + date.getDate() : date.getDate();
    //Time
    var h = date.getHours();
    //Minute
    var m = date.getMinutes();
    //Second
    var s = date.getSeconds ();
  
    console.log("当前时间:" +Y+M+D+h+":"+m+":"+s);
    
//Convert to time format string
    console.log(date.toDateString());

    console.log(date.toGMTString());

    console.log(date.toISOString());
  
    console.log(date.toJSON());
    
    console.log(date.toLocaleDateString());

    console.log(date.toLocaleString());
  
    console.log(date.toLocaleTimeString());
   
    console.log(date.toString());
   
    console.log(date.toTimeString());
   
    console.log(date.toUTCString());

//Add and subtract time and timestamp to add one day as an example, you must be smart by analogy
    //Add a day's timestamp:
    var tomorrow_timetamp = timestamp + 24 * 60 * 60;
    //Add the time of day:
    var n_to = tomorrow_timetamp * 1000;
    var tomorrow_date = new Date(n_to);
    //add the year after one day
    var Y_tomorrow = tomorrow_date.getFullYear();
    // month after adding one day
    var M_tomorrow = (tomorrow_date.getMonth() + 1 < 10 ? '0' + (tomorrow_date.getMonth() + 1) : tomorrow_date.getMonth() + 1);
    //Add the date after one day
    var D_tomorrow = tomorrow_date.getDate() < 10 ? '0' + tomorrow_date.getDate() : tomorrow_date.getDate();
    //Add the time after one day
    var h_tomorrow = tomorrow_date.getHours();
    // add minutes after one day
    var m_tomorrow = tomorrow_date.getMinutes();
    //Add seconds after one day
    var s_tomorrow = tomorrow_date.getSeconds();




Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324885442&siteId=291194637