转换整数时间facebook消息时间 - javascript

时间:2017-05-07 16:40:47

标签: javascript jquery json facebook facebook-javascript-sdk

如何隐藏这个时间和#34; 08:45 PM"

json时间码

{"time":1480797244,"short":false,"forceseconds":false}

我这次需要隐蔽(1480797244)需要jQuery或javascript中的想法

1 个答案:

答案 0 :(得分: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))