背景
因为要和后台进行时间格式进行统一,然后涉及到表单打开时候的初始化问题,但直接传入new Date() ,element-ui 会将数据转换为要求的格式显示,但实际值还是new Date()对象,而不是yyyy-MM-dd HH:mm:ss,尽管我已经在上边约束了,没办法只能手写个初始化方法了
直接放代码
initDate(){ let now = new Date() let y=now.getFullYear(); let m=now.getMonth() + 1 >9?now.getMonth() + 1 :"0"+(now.getMonth() + 1); let d= now.getDate()>9?now.getDate() :"0"+now.getDate(); let h=now.getHours()>9?now.getHours() :"0"+now.getHours(); let i=now.getMinutes()>9?now.getMinutes() :"0"+now.getMinutes(); let s= now.getSeconds()>9?now.getSeconds() :"0"+now.getSeconds(); return y+'-'+m+'-'+d+' '+h+':'+i+':'+s }
标签:初始化,getMinutes,ss,dd,yyyy,MM,HH,let,now From: https://www.cnblogs.com/piaohd/p/17685665.html