12345678910111213 |
- //1.格式化时间
- export function formatLocalDate(date) {
- const birthday = new Date(date); // 创建 Date 对象
- const year = birthday.getFullYear();
- const month = String(birthday.getMonth() + 1).padStart(2, '0'); // 月份从 0 开始,所以加 1
- const day = String(birthday.getDate()).padStart(2, '0');
- const hours = String(birthday.getHours()).padStart(2, '0');
- const minutes = String(birthday.getMinutes()).padStart(2, '0');
- const seconds = String(birthday.getSeconds()).padStart(2, '0');
- // 返回格式化后的字符串
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
- }
|