2017-05-07 49 views

回答

1

使用以下方法將時間戳轉換爲您所需的格式。檢查Updated fiddle

function formatAMPM(timestamp) { 

    date = new Date(timestamp * 1000) 
    var month = ("0" + (date.getMonth() + 1)).slice(-2); 
    var year = date.getFullYear(); 
    var day = date.getDate(); 
    var hours = date.getHours(); 
    var minutes = date.getMinutes(); 
    var ampm = hours >= 12 ? 'pm' : 'am'; 
    hours = hours % 12; 
    hours = hours ? hours : 12; // the hour '0' should be '12' 
    minutes = minutes < 10 ? '0'+minutes : minutes; 
    var strTime = day + '/' + month + '/' + year + ' ' + hours + ':' + minutes + ' ' + ampm; 
    return strTime; 
} 

var timeObj = {"time":1480797244,"short":false,"forceseconds":false}; 
alert(formatAMPM(timeObj.time)) 
+0

我需要添加月,日和年,我怎麼能做到這一點? –

+0

@ Abdo-Host更新了小提琴。請立即檢查 –

+0

是否適合您? –