0

I have a mobile application which authenticates the user via a phone number (similar to Whatsapp's sign in process).

After the user has logged in, he can create a TODO notes. When he creates a note he also fills in a date.

In the DB, I want to normalize this date to UTC.
So for example, if the user filled the date: 06/07/2015 17:00:00
And the UTC offset in his country is +3
Then 06/07/2015 14:00:00 will be saved in the DB.

In order to do this, I need to know the UTC offset of the user's country.

When the user registered the only two things he provided are:

  • country code
  • phone number

Those are not enough to know the UTC offset, because a user who entered a country code of US can still be in several different time zones.

I am also using libphonenumber to parse the incoming values mentioned above, but it can't get me the offset I want.

How can this be solved ? (How other apps like Viber, Line and Whatsapp handle this scenario?)

4

2 回答 2

1

我想把你的问题改成这样:

如何从电话号码中获取时区?

答案是,,您不能仅从电话号码(包括国家/地区代码)中获取时区。

我要做的是查看客户端向您发送完整DateTimeOffset的 (包括时区)或DateTime带有某种“位置”的客户端,然后您尝试在服务器上自己引出它。

于 2015-07-06T15:27:07.507 回答
0

正如 Alexi 所说,最好的办法是永远不要在服务器端处理 UTC 转换。相反,客户端将发送已采用 UTC 的日期。根据操作系统中定义的时间偏移(即语言环境),与 UTC 的转换将始终在客户端完成。服务器仅从客户端获取 UTC 日期。

于 2015-07-06T22:37:37.783 回答