Last active
August 28, 2019 06:36
-
-
Save mugyu/78b1956aa63355feaf033549f17fe6fa to your computer and use it in GitHub Desktop.
現在時刻を `YYYYMMDDHHmm` のフォーマットにして返す in JavaScript
This file contains hidden or 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
/** | |
* 取得 現在年月日時分 | |
* @return{string} 現在時刻をベースにした YYYYMMDDHHmm | |
*/ | |
function get_datetime_string() { | |
const datetime = new Date(); | |
const year = datetime.getFullYear(); | |
const month = datetime.getMonth() + 1; | |
const day = datetime.getDate(); | |
const hours = datetime.getHours(); | |
const minutes = datetime.getMinutes(); | |
return String( | |
year * 100000000 | |
+ month * 1000000 | |
+ day * 10000 | |
+ hours * 100 | |
+ minutes | |
); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment