[英]jQuery: Change Date Format
我已按照此鏈接上的教程: http : //trulycode.com/bytes/easy-countdown-to-date-with-javascript-jquery/
我如何更改日期格式
$("#countdown").countdown({
date: "8 September 2020 09:00:00",
format: "on"
});
從:
date: "8 September 2020 09:00:00",
至:
date: "2020-9-8 09:00:00",
希望有人能幫助我。
你可以解析它,然后顯示你想要的:
var date = new Date(Date.parse("8 September 2020 09:00:00"))
var newFormat = '' + date.getFullYear() + '-' + (date.getMonth() + 1) + '-' + date.getDate() + ' ' + date.toTimeString().slice(0,8)
// -> 2020-9-8 09:00:00
請注意, getMonth()
索引從0開始,因此9月將為8,這就是為什么如果希望它為9則必須添加1。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.