javascript - 日期格式的名称是什么,如何仅在 html 中显示日期?2020 年 8 月 24 日星期一 00:00:00 GMT+0800(新加坡标准时间)
问题描述
我正在使用 postgresSQL 数据库。我添加了一个日期列,在 pgadmin 中插入一条记录后,日期字段看起来像“24-08-2020”。但是,当我尝试从数据库中渲染/检索并在 html 中显示时,日期字段看起来像这样“Mon Aug 24 2020 00:00:00 GMT+0800 (Singapore Standard Time)”。我只想以这种格式 dd/mm/yyyy 显示日期。postgres 中是否有任何查询,或者我应该在 js 上工作?
解决方案
您可以将其转换为 unix 时间戳并使用它。使用 Date 类函数取出日、月、年。
const allmonths = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
const day = (d) => {
if (d < 10)
return '0' + d;
return d;
};
const dt = new Date('Mon Aug 24 2020 00:00:00 GMT+0800')
const dtFormat = day(dt.getDate()) + '-' +allmonths[dt.getMonth()] + '-' + dt.getFullYear() // 24-08-2020
推荐阅读
- html - 比较 HTML 文件中的 2 个字符串 - Angular
- php - PHP import_request_variables 的正确(安全)替代方案是什么?
- maven - 可运行的 jar 生产模式:找不到捆绑清单文件 'frontend://vaadin-flow-bundle-manifest.json'
- java - 实用地检测 MIUI/小米设备中的软导航栏可用性?
- javafx - JavaFX | 改变线锚?
- php - Yii2:视图中的全局变量
- typescript - 具有指定参数的函数
- php - 在主题类中找不到 PhpStorm 方法
- spring-boot - 使用 Flyway 和 Spring Boot 迁移基线
- python - Python:CSV 编写器非常慢,需要建议以加快速度