Date 对象,是操作日期和时间的对象. Date 为内置的构造函数, 通过 new Date () 来获取当前本地日期与时间 const time = new Date console.log(time )//Mon Nov 05 2018 15:20:49 GMT+0800 传参 传递Number 将从 '1970/01/01 00:00:00' 为起点,开始叠加的毫秒数,传入负值将倒退. time(1000)//Thu Jan 01 1970 08:00:01 GMT+0800 (中国…
问题背景:想把一个时间直接转成字符串格式 通过查api发现有个toLocaleString(),根据本地时间格式,把 Date 对象转换为字符串 new Date().toLocaleString(); //"2018/5/31 下午1:43:06" 但是默认是12小时制,会带这种上午下午,所以肯定不需要,继续查,发现可以配置 ; (new Date(ss).toLocaleString('chinese',{hour12:false})).replace(/\//g,'-'); //…