js有什么简便的方法把2017-4-5变为2017-04-05这种格式
js有什么简便的方法把2017-4-5变为2017-04-05这种格式 |
免责声明:本内容仅代表回答会员见解不代表天盟观点,请谨慎对待。
版权声明:作者保留权利,不代表天盟立场。
|
|
|
|
window.onload=function(){ vardates="2017-5-4"; vardate=newDate(dates); alert(formateDate(date)); } functionformateDate(date){ vary=date.getFullYear(); varm=date.getMonth()+1; vard=date.getDate(); varh=date.getHours(); varmi=date.getMinutes(); vart=date.getSeconds(); m=m>9?m:'0'+m; d=d>9?d:'0'+d; mi=mi>9?mi:'0'+mi; t=t>9?t:'0'+t; returny+'-'+m+'-'+d+''+h+':'+mi+':'+t; } </script> |
|
|
|
|
str.split('-').map(item=>item.padStart(2,0)).join('-')str.split('-').map(item=>item.padStart(2,0)).join('-')str.split('-').map(item=>item.padStart(2,0)).join('-')str.split('-').map(item=>item.padStart(2,0)).join('-') |
|
|
|
|
DYEPSVVRFSFF
MOEHXQQDQTDC
VHXNUHWRXNKB
IBQAAKJYFRHX
KWLIBQAJJZSB
AMVVINDMCXDD
ZCCVFLAGJZAK
RKGWITPQTZPS
VHREKUAWDTJV
XFLIPYUKHDGG
GSMIGDPGCICB
BXMCZVRNKCIO
NQHKADPCCIIU
IUGORUTJGWVC
SIROURBXEEKG
EWJGMPLYGWZZ
JSHSPYLUAQDT
MLRRZNJZWISC
FKQGTFBIDGSZ
CYENNKOKNDKP
COAOVJCVMCFB
MOAWEIIILLYD
YXAPZVRVOBLQ
EQCYZPPOVVLX
GPDMCVONMZGZ
PMSKGZZXJZTC
UDCLBOBXDCYU
IBWMCUDTTTHD
PLIXOAFOGCPL
YKGNBKATGVRN
RANAQTZMSCAG
VDGMMQMZMFNJ
RPMWMIFLODWP
PBAAQAHNKQBU
SIMDHAGZPWSI
CUKQWTHENDKW
PZFVKEDJQWTF
RAPCSOBYKKAO
LBNHHKGNIPIL
WVRCQQPWFFLV
XTSSMMNMWSHY
DSEOEXXDTZPJ
RNNDEKUBHIST
UHWMMCYV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