Joeyne
5/8/2019 - 6:07 PM

getLocate

/** get Locale by timestamp **
* @Param timestamp int
* @return string
*
* var mydate=new Date(); 
* var myyear=mydate.getFullYear(); 
* var mymonth=mydate.getMonth()+1;// 注:月数从 0~11 为一月到十二月 
* var mydat=mydate.getDate(); 
* var myhours=mydate.getHours(); 
* var myminutes=mydate.getMinutes(); 
* var myseconds=mydate.getSeconds() 
* var myday=mydate.getDay()// 注: 0-6 对应为星期日到星期六 
*/
let getLocale = function(timestamp) {
    if (timestamp.toString().length === 10) {
        timestamp += parseInt(timestamp.toString() + '000');
    }
    let date = new Date(timestamp);
    let [y, m, d, h, i, s] = [
        date.getFullYear(),
        (date.getMonth() + 1).toString().padStart(2, '0'),
        date.getDate().toString().padStart(2, '0'),
        date.getHours().toString().padStart(2, '0'),
        date.getMinutes().toString().padStart(2, '0'),
        date.getMinutes().toString().padStart(2, '0')
    ];
    return y + '-' + m + '-' + d + ' ' + h + ':' + i + ':' + s;
}
let locale = getLocale(1537097957);
console.log(locale);