Date.prototype.toLocaleDateString([locales][, options])
locales
可选。包含⼀种或多种语⾔或区域设置标记的区域设置字符串数组。如果包含多个区域设置字符串,请以降序优先级对它们进⾏排列,确保⾸个条⽬为⾸选区域设置。如果省略此参数,则使⽤ JavaScript 运⾏时的默认区域设置。有关更多信息,请参见备注部分。options
可选。包含指定⽇期和时间格式设置选项的⼀个或多个特性的对象。有关详细信息,请参见“备注”部分。
Date转字符串-直接使⽤版
let datetime = new Date();
let dt = datetime.toLocaleString();console.log(dt);//2020-5-4 23:06:56
Date转字符串-⾼级版
let options = {
year : \"numeric\ month : \"2-digit\ day : \"2-digit\ hour : \"2-digit\ minute : \"2-digit\ second : \"2-digit\};
let datetime = new Date().toLocaleString(\"zh-CN\console.log(datetime);//2020-05-04 23:09:40
因篇幅问题不能全部显示,请点此查看更多更全内容