Last active
September 20, 2021 21:36
-
-
Save ntuaha/f4b16ad377505a8519c7 to your computer and use it in GitHub Desktop.
Javascript 漂亮日期顯示 YYYYMMDDhhmmss or YYYY-MM-DD hh:mm:ss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
function pad(v){ | |
return (v<10)?'0'+v:v | |
} | |
function getDateString(d){ | |
var year = d.getFullYear(); | |
var month = pad(d.getMonth()+1); | |
var day = pad(d.getDate()); | |
var hour = pad(d.getHours()); | |
var min = pad(d.getMinutes()); | |
var sec = pad(d.getSeconds()); | |
return year+month+day+hour+min+sec; | |
//return year+"-"+month+"-"day+" "+hour+":"+min+":"+sec; | |
//YYYYMMDDhhmmss | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pad = (v) => { | |
return (v<10)?'0'+v:v | |
} | |
const getDateString = (d) => { | |
let year = d.getFullYear() | |
let month = pad(d.getMonth()+1) | |
let day = pad(d.getDate()) | |
let hour = pad(d.getHours()) | |
let min = pad(d.getMinutes()) | |
let sec = pad(d.getSeconds()) | |
//YYYYMMDDhhmmss | |
return year+month+day+hour+min+sec | |
//YYYY-MM-DD hh:mm:ss | |
//return year+"-"+month+"-"day+" "+hour+":"+min+":"+sec | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
感謝