<> How to convert timestamps to time formatted strings

** Server return time is a string of numbers with Unix Starting from the first year of time , Return the corresponding time stamp
** Time stamp is seconds

* Convert timestamps to Date object ( millisecond )
* take Date Format , Convert to corresponding string
** format (data,‘yyyy-MM-dd hh:mm:ss’)

y:year year
M:Month month ( Capitalized , Make a distinction with minutes )
d:day day
h:hours hour (h,12 hour / H,24 hour )
m:minutes minute
s:seconds second

** What is regular expression for ?
** string matching
<> Matching rules
+: One or more
*:0 One or more
?:0 One or one

1. Get year
if (/(y+)/.test(fmt)) { fmt = fmt.replace(RegExp.$1, (date.getFullYear() + '').
substr(4 - RegExp.$1.length)); }
** I don't know how many others sent y, First, check the information from others y Number of
** RegExp.$1 It's a match y Replace it with the following result
** date.getFullYear() + ’ ’ Convert year numbers to strings
** substr() Number of interceptions
<> The code is as follows function formatDate(date, fmt) { // Get year if (/(y+)/.test(fmt)) { fmt =
fmt.replace(RegExp.$1, (date.getFullYear() + '').substr(4 - RegExp.$1.length));
} // Get more let o = { 'M+': date.getMonth() + 1, 'd+': date.getDate(), 'h+': date.
getHours(), 'm+': date.getMinutes(), 's+': date.getSeconds() }; for (let k in o)
{ if (new RegExp(`(${k})`).test(fmt)) { let str = o[k] + ''; fmt = fmt.replace(
RegExp.$1, (RegExp.$1.length === 1) ? str : padLeftZero(str)); } } return fmt; }
; function padLeftZero(str) { return ('00' + str).substr(str.length); };
Why separate the year from others ?
Year may display two digits Two digits may also be displayed
Because if the time required to be displayed is Time, minute and second are two bits
padLeftZero Algorithm complements two bits

Technology
©2019-2020 Toolsou All rights reserved,
java Four functional interfaces ( a key , simple )os Simple use of module HashMap Explain in detail html Writing about cherry trees , Writing about cherry trees It's unexpected Python Cherry tree (turtle The gorgeous style of Library ) computer network --- Basic concepts of computer network ( agreement , system ) Some East 14 Pay change 16 salary , Sincerity or routine ? Browser kernel ( understand )