javascript 前端 vue.js 开发语言 ecmascript Wed Jan 04 2027 00:00:00 GMT+0800 (中国标准时间) js中转为 yyyy-mm-dd hh:mm:ss格式 - + (hour <
在 JavaScript 中可以使用 Date 对象转换日期格式。可以使用 getFullYear(),getMonth(),getDate(),getHours(),getMinutes(),getSeconds() 方法获取相应的年月日时分秒。
下面是一个将 Wed Jan 04 2023 00:00:00 GMT 0800 (中国标准时间) 转换为 "yyyy-mm-dd hh:mm:ss" 格式的示例代码:
letdate = new Date("Wed Jan 04 2023 00:00:00 GMT 0800 (中国标准时间)");
let year = date.getFullYear();
let month = date.getMonth() + 1; // getMonth()返回值是0~11
let day = date.getDate();
let hour = date.getHours();
let minute = date.getMinutes();
let second = date.getSeconds();
let result = year + "-" + (month < 10 ? "0" + month : month) + "-" + (day < 10 ? "0" + day : day) + " " + (hour < 10 ? "0" + hour : hour) + ":" + (minute < 10 ? "0" + minute : minute) + ":" + (second < 10 ? "0" + second : second); 拼多多帮助力入口
console.log(result);
// output: "2023-01-04 00:00:00"
精彩文章