Method for converting year, month, day, hour, minute, and second
function formatTime(date) { const year = date.getFullYear(); const month = date.getMonth() + 1; const day = date.getDate(); const hour = date.getHours(); const minute = date.getMinutes(); const second = date.getSeconds(); return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':'); } const formatNumber = (n) => { const str = n.toString(); return str[1] ? str : '0' + str; };
Time zone conversion method
/*****
* i is the time zone value
* timeVal incoming timestamp
*******function getLocalTime(i, timeVal) {
// Parameter i is the time zone value number, for example, Beijing is the East Eight District, enter 8, West 5 enter -5 if (typeof i! == 'number') return; var d = new Date (timeVal); // get The number of seconds from January 1, 1970 to the present var len = timeVal; // The time offset difference between local time and GMT time var offset = d.getTimezoneOffset () * 60000; // Get the current Greenwich time var utcTime = len + offset; return formatTime (new Date (utcTime + 3600000 * i)); }
console.log (getLocalTime (7, 1586941817471)); // The time in the East 7 area, Bangkok, Thailand, if you do your own test, it is better than Beijing Just an hour short.
Eastern Time:
Zero time zone-London time
East 1st District-Berlin Time
East Second District-Athens Time
Eastern Third District-Moscow Time
East Five District-Islamabad Time
East Six District-Colombo Time
East Seven District-Bangkok Time
East Eight District-Beijing Time
East Kowloon-Tokyo Time
East Ten District-Sydney Time
East Twelve District-Fiji Time
Western Time:
West Tenth District-Fiji Time
West Nine District-Alaska Time
Western Eight District-Pacific Time (United States and Canada)
West Seven District-Mountain Time (USA and Canada)
West Sixth District-Central Time (United States and Canada)
West Five District-Eastern Time (USA and Canada)
West Fourth District-Atlantic Time (Canada
West Third District-Brasilia Time