Created
October 21, 2024 12:47
Javascriptで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
const getYMD = () => { | |
const one2 = (num) => (num <= 9 ? `0${num}` : num); | |
const now = new Date(); | |
const yy = now.getFullYear(); | |
const mm = one2(now.getMonth()+1); | |
const dd = one2(now.getDate()); | |
const h = one2(now.getHours()); | |
const m = one2(now.getMinutes()); | |
const s = one2(now.getSeconds()); | |
return `${yy}-${mm}-${dd} ${h}:${m}:${s}`; | |
// return `${yy}-${mm}-${dd} ${h}:${m}:${s}`; | |
// return `${yy}-${mm}-${dd} ${h}:${m}`; | |
// return `${yy}-${mm}-${dd}`; | |
// return `${h}:${m}:${s}`; | |
// return `${h}:${m}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment