Sequlize js/express js/node js 如何更改日期格式 [英] Sequlize js / express js / node js how to change the date format

查看:31
本文介绍了Sequlize js/express js/node js 如何更改日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我看到存储在我的数据库中的日期时.

When I see the dates stored in my database.

这是正常.日期和时间就是这样.

This is normal. The date and the time that's all.

但是当我运行 get 请求来获取数据时.

But when I run a get request to get the data.

此格式与存储在数据库中的格式不同.为什么会发生这种情况?

THIS FORMAT IS NOT SAME AS THE FORMAT THAT STORED IN THE DATABASE. Why could this happen?

推荐答案

我们不需要为这些事情安装任何包,因为我们可以使用 MySQL 本身来处理日期格式从你的照片我可以看出你正在使用 MySQL

We need not install any package for these kind of things as we can handle the date formats using MySQL itself From your pic I can see you are using MySQL

只需使用 MySQL 中的 dateformat

Just use dateformat from MySQL

Select id, date_format(createdAt, '%d-%m-%Y %r') from table_name;

注意:%r 表示上午或下午的时间

深入了解:https://www.w3schools.com/sql/func_mysql_date_format.asp

如需进一步帮助,您可以评论

这篇关于Sequlize js/express js/node js 如何更改日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆