[英]All users to have exactly the same date and time
So I would like that all my users would have the same date and time no matter their location. 因此,我希望所有用户,无论他们身在何处,都拥有相同的日期和时间。 Even if they have changed date and time settings the date and time in the application would not change. 即使他们更改了日期和时间设置,应用程序中的日期和时间也不会更改。
At the moment I have constructed a string which is based on every user's 'iPhone time'. 目前,我已经构造了一个基于每个用户的“ iPhone时间”的字符串。
let todaysDate: String = {
let date = Date()
let formatter = DateFormatter()
formatter.dateFormat = "yyyy-MM-dd"
let result = formatter.string(from: date)
return result
}()
My wish is that every user would have EET (Eastern Europe Time). 我希望每个用户都拥有EET(东欧时间)。
Just set the time zone of your dateformatter to EET if you need the time/date to be independent of user location. 如果您需要时间/日期与用户位置无关,只需将dateformatter的时区设置为EET。
formatter.timeZone = TimeZone(abbreviation: "EET")
However, Date()
returns the current device time, so if the user changes their date/time setting, you would get wrong results. 但是, Date()
返回当前设备时间,因此,如果用户更改其日期/时间设置,则会得到错误的结果。 To always get a correct data, you have to rely on a date fetched from a reliable server. 为了始终获取正确的数据,您必须依靠从可靠服务器获取的日期。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.