現在時刻を 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
);
}