首页
/
每日頭條
/
生活
/
js怎麼轉成日期
js怎麼轉成日期
更新时间:2024-12-23 15:55:14

js怎麼轉成日期?/** * 日期格式化,接下來我們就來聊聊關于js怎麼轉成日期?以下内容大家不妨參考一二希望能幫到您!

js怎麼轉成日期(js時間轉化格式)1

js怎麼轉成日期

/**

* 日期格式化

* @param {時間對象} date

* @param {字符串} str

* @param {布爾值} isTime

* @param {tiemStr} str

*/

function formatDate(date, isTime = false, str = '-', tiemStr = ':'){

date = new Date(date)

let Y = date.getFullYear()

let M = (date.getMonth() 1) < 10 ? '0' (date.getMonth() 1) : date.getMonth() 1

let D = date.getDate() < 10 ? '0' date.getDate() : date.getDate()

if(isTime){

let h = date.getHours() < 10 ? '0' date.getHours() : date.getHours()

let m = date.getMinutes() < 10 ? '0' date.getMinutes() : date.getMinutes()

let s = date.getSeconds() < 10 ? '0' date.getSeconds() : date.getSeconds()

return Y str M str D ' ' h tiemStr m tiemStr s

}

return Y str M str D

}

export { formatDate}

,
Comments
Welcome to tft每日頭條 comments! Please keep conversations courteous and on-topic. To fosterproductive and respectful conversations, you may see comments from our Community Managers.
Sign up to post
Sort by
Show More Comments
Copyright 2023-2024 - www.tftnews.com All Rights Reserved