Skip to content

Instantly share code, notes, and snippets.

@mugyu
Last active August 28, 2019 06:36
Show Gist options
  • Save mugyu/78b1956aa63355feaf033549f17fe6fa to your computer and use it in GitHub Desktop.
Save mugyu/78b1956aa63355feaf033549f17fe6fa to your computer and use it in GitHub Desktop.
現在時刻を `YYYYMMDDHHmm` のフォーマットにして返す in JavaScript
/**
* 取得 現在年月日時分
* @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