数据库中商店日期时间的最佳实践是什么?
我正在为商店客户从Frontend侧和我的情况进行购买订单表,而我的情况是:
- 客户将来自不同国家 /地区,
- 我的数据库服务器时区在UTC+1
- 日光保存时间上可能适用某些国家 /地区可能适用的
- 某些客户可能会购买来自A国家的产品,然后第二天从B国购买另一种产品,但在不同的时区,
- 一些客户(旅行者)来自A(UTC+2),并通过他的手机(UTC)在B(UTC+0)购买商品(UTC +3,我不知道为什么,但是它们是)
这是我的问题:
- 将数据库存储在数据库中的最佳实践是什么?
- 前端侧是否需要将时区从客户端转换为数据库?
- 后端是否需要将时区从数据库转换为客户端?如何确定客户当前的时区?
- 显示DateTime从服务器到网站以进行客户评论的最佳实践是什么?
- (new)如何处理
可用_DELIVERY_DATE
和oparive_delivery_time
客户端输入哪些字段?
==================
[更新1] 关于问题点5的添加说明,我的订单表有2个名为oparive_delivery_date
和oparity_delivery_time
客户端以timezone输入的字段 oparity_delivery_time 保存记录的最佳实践是什么?
I am working on buy order table for store client's record from frontend side and my case:
- Client would which come from different countries, different timezones
- My database server timezone is on UTC+1
- Daylight saving time might apply in some countries
- Some clients might buy a product from country A, then buy another product from country B the next day but on different timezones
- Some client (travelers) which come from country A (UTC+2) and bought items in country B (UTC+0) via his phone (UTC+3, I don't know why but they are)
Here are my questions:
- What is the best practice to store the datetime in the database?
- Does frontend side need to convert timezones from client to database?
- Does backend side need to convert timezones from database to client? How do I determine a client's current timezone?
- What is the best practice to show datetime from server to website for client review?
- (New) How do I handle
available_delivery_date
andavailable_delivery_time
which those fields input by client?
==================
[ Update 1 ]
An addition description about question point 5, my order table have 2 fields named available_delivery_date
and available_delivery_time
which input by client with their timezone, what is the best practice to save the record?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
一切都取决于未来的用例和您的要求。任何最适合您的方法都不是标准格式。
将数据库存储在数据库中的最佳实践是什么?
- 如果您需要在DateTime或Timestamp中使用Date Store进行购买日期将其进行计算。也可以在计算之前作为VARCHAR存储和解析。
前端端是否需要将时区从客户端转换为数据库?
- 将后端使用一种标准时间格式,并在服务器日期和时间的响应通过日期,以便您的时间是所有用户的标准时间。
后端侧是否需要将时区从数据库转换为客户端?我如何确定客户当前的时区?
- 使用服务器的日期和时间,以使您的时间格式与众不同。
显示DateTime从服务器到网站的最佳实践是什么??
- 最好的做法是使用后端在插入查询上插入服务器时间,以便服务器时间是所有用户的标准时间。您可以获取行并将其传递给基于服务器时间的前端
Everything is depending on future use cases and your requirement. No format is standard whatever works best for you.
What is the best practice to store the datetime in the database?
-If you need to perform calculation like days from purchase using date store it in either datetime or timestamp. Storing as varchar and parsing before calculation also can be done.
Does frontend side need to convert timezones from client to database?
-Make backend use one standard time format and on response pass date from server date and time so that your time would be standard for all users.
Does backend side need to convert timezones from database to client? How do I determine a client's current timezone?
-Use servers date and time to standarize your time formats.
What is the best practice to show datetime from server to website for client review?
-Best practice is to use backend to insert server time on insert query so that server time would be standard for all users. You can fetch the row and pass it to frontend which is based on server time