我想知道如何从时间戳中获取特定日期格式(日期或月份或日期或年份)。我想在Backbone JS的视图中使用它
答案 0 :(得分:10)
var d = new Date(1397639141184);
alert(d.getDate() + '/' + (d.getMonth()+1) + '/' + d.getFullYear());
答案 1 :(得分:0)
1.如果是JavaScript时间戳(即以毫秒为单位)
var date = new Date(13976391000);
var date = date.getDate(); //returns date (1 to 31) you can getUTCDate() for UTC date
var day = date.getMonth(); // returns 1 less than month count since it starts from 0
var year = date.getFullYear(); //returns year
// You can also use getHours(), getMinutes() and so on
2.如果是数据库时间戳 - 示例2013-03-14T02:15:00
var date = new Date('2013-03-14T02:15:00'); // Works in all browsers
var date = new Date('2013-10-18 08:53:14');// works in Chrome & doesn't work in IE/Mozilla
//note that its a string and you use the same above functions to get Date,month & year