我有一個Json時間戳,我想使用javascript將其轉換爲簡單的日期時間格式。將json時間戳轉換爲javascript中的正常日期和時間
我需要以下列格式的日期和時間:DD-MM-YYYY小時:mn個
這裏是從i希望提取時間戳的示例JSON日期: 「時間戳」:1326439500
{
"count": 2,
"d": [
{
"title": "Apple iPhone 4S Sale Cancelled in Beijing Amid Chaos (Design You Trust)",
"description": "Advertise here with BSA Apple cancelled its scheduled sale of iPhone 4S in one of its stores in China’s capital Beijing on January 13. Crowds outside the store in the Sanlitun district were waiting on queues overnight. There were incidents of scuffle between shoppers and the store’s security staff when shoppers, hundreds of them, were told that the sales [...]Source : Design You TrustExplore : iPhone, iPhone 4, Phone",
"link": "http://wik.io/info/US/309201303",
"timestamp": 1326439500,
"image": null,
"embed": null,
"language": null,
"user": null,
"user_image": null,
"user_link": null,
"user_id": null,
"geo": null,
"source": "wikio",
"favicon": "http://wikio.com/favicon.ico",
"type": "blogs",
"domain": "wik.io",
"id": "2388575404943858468"
},
{
"title": "Apple to halt sales of iPhone 4S in China (Fame Dubai Blog)",
"description": "SHANGHAI – Apple Inc said on Friday it will stop selling its latest iPhone in its retail stores in Beijing and Shanghai to ensure the safety of its customers and employees. Go to SourceSource : Fame Dubai BlogExplore : iPhone, iPhone 4, Phone",
"link": "http://wik.io/info/US/309198933",
"timestamp": 1326439320,
"image": null,
"embed": null,
"language": null,
"user": null,
"user_image": null,
"user_link": null,
"user_id": null,
"geo": null,
"source": "wikio",
"favicon": "http://wikio.com/favicon.ico",
"type": "blogs",
"domain": "wik.io",
"id": "16209851193593872066"
}
]
}
var date = new Date(timestamp)var hours = date.getHours(); //來自時間戳的分鐘部分 var minutes = date.getMinutes(); //秒時間戳部分 var seconds = date.getSeconds(); //將以10:30:23格式顯示時間 var formattedTime =小時+':'+分鐘+':'+秒; –
@RajatSinghal只會給出時間不是嗎? – praneybehl
你可以從日期對象中獲取日期,年份...而不是gethours使用getYear ... –