我应该如何处理客户端 - 服务器应用程序上的时区?

时间:2022-10-28 20:44:48

I have an iOS application and a rails backend.

我有一个iOS应用程序和一个rails后端。

The iOS client allows user to pick Dates in the (Year|Month|Day) format. No time is necessary, it's preferable if 00:00:00 is used.

iOS客户端允许用户以(年|月|日)格式选择日期。没有时间,如果使用00:00:00,则更可取。

What's the best practice for this, and what should I use?

什么是最好的做法,我应该使用什么?

1) Should the client convert times into UTC, and then save those to the server. And then when the client fetches times, convert it back into the user local time?

1)客户端是否应将时间转换为UTC,然后将其保存到服务器。然后当客户端提取时间时,将其转换回用户本地时间?

2) Should the client just push up whatever time it wants, and leave it for the server to decide what to do with it?

2)客户应该随时推送它,并留给服务器决定如何处理它?

1 个解决方案

#1


0  

Here's what I'm doing with my apps:

这是我正在使用我的应用程序:

Backend/server only deals with UTC. Always store times in UTC into the MySQL database (or whatever database you're using).

后端/服务器仅处理UTC。始终将UTC时间存储到MySQL数据库(或您正在使用的任何数据库)中。

Push the conversion of time differences logic to the client. Most clients have a third party solution dealing with conversion of time (for iOS, check: https://github.com/yannickl/YLMoment ).

将时差逻辑的转换推送到客户端。大多数客户都有第三方解决方案来处理时间转换(对于iOS,请检查:https://github.com/yannickl/YLMoment)。

In mobile clients, I would still store the times in UTC into the local database. The only time I do any conversion is when the date is being displayed on the UI. This allows for users to travel into different timezones and the dates will be updated to reflect the local timezone.

在移动客户端中,我仍然将UTC中的时间存储到本地数据库中。我进行任何转换的唯一时间是在UI上显示日期。这允许用户进入不同的时区,并且将更新日期以反映当地时区。

#1


0  

Here's what I'm doing with my apps:

这是我正在使用我的应用程序:

Backend/server only deals with UTC. Always store times in UTC into the MySQL database (or whatever database you're using).

后端/服务器仅处理UTC。始终将UTC时间存储到MySQL数据库(或您正在使用的任何数据库)中。

Push the conversion of time differences logic to the client. Most clients have a third party solution dealing with conversion of time (for iOS, check: https://github.com/yannickl/YLMoment ).

将时差逻辑的转换推送到客户端。大多数客户都有第三方解决方案来处理时间转换(对于iOS,请检查:https://github.com/yannickl/YLMoment)。

In mobile clients, I would still store the times in UTC into the local database. The only time I do any conversion is when the date is being displayed on the UI. This allows for users to travel into different timezones and the dates will be updated to reflect the local timezone.

在移动客户端中,我仍然将UTC中的时间存储到本地数据库中。我进行任何转换的唯一时间是在UI上显示日期。这允许用户进入不同的时区,并且将更新日期以反映当地时区。