The front-end processes the time (System.currentTimeMillis) obtained by the back-end

    If the java backend gets the current time using the System.currentTimeMillis long type, the front-end js can format the time by the following method

var time = 1519609707542;
    time = new Date(time);
    time = time.toLocaleString();
    console.log(time);

The time format returned in this way is: 2018/2/26 9:48:27 am

another date format

var time = 1519609707542;
    time = new Date(time);
    console.log(time);

The time format returned in this way is: Mon Feb 26 2018 09:48:27 GMT+0800 (China Standard Time)

There is also this fully custom:

var time = 1519609707542;
    time = new Date(time);
    var year = time.getFullYear();
    var month = time.getMonth() + 1;//月份是从0-11
    var day = time.getDate();//getDay()是获取星期getDate()是获取天1-31
    console.log(year + '/' + month + '/' + day + ' ' + time.getHours() + ':' + time.getMinutes() + ':' + time.getSeconds());

The time format returned in this way is: 2018/2/26 9:48:27

Tips: The following is the method to get the date through js:

var myDate = new Date();
myDate.getYear();        //获取当前年份(2位)
myDate.getFullYear();    //获取完整的年份(4位,1970-????)
myDate.getMonth();       //获取当前月份(0-11,0代表1月)
myDate.getDate();        //获取当前日(1-31)
myDate.getDay();         //获取当前星期X(0-6,0代表星期天)
myDate.getTime();        //获取当前时间(从1970.1.1开始的毫秒数)
myDate.getHours();       //获取当前小时数(0-23)
myDate.getMinutes();     //获取当前分钟数(0-59)
myDate.getSeconds();     //获取当前秒数(0-59)
myDate.getMilliseconds();    //获取当前毫秒数(0-999)
myDate.toLocaleDateString();     //获取当前日期
var mytime=myDate.toLocaleTimeString();     //获取当前时间
myDate.toLocaleString( );        //获取日期与时间

 

Guess you like

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