简体   繁体   English

所有用户具有完全相同的日期和时间

[英]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.

相关问题 NSMutableArray项完全相同 - NSMutableArray items are all exactly the same 在Firebase(Swift)中让所有用户成为同一个孩子 - Getting all the users same child in Firebase (Swift) 将datePicker日期和计时器与用户Date和Time匹配(swift3) - match datePicker date and timer with users Date and Time (swift3) UIScrollViews在同一时间所有滚动 - UIScrollViews all scroll in the same time 在保持时间不变的情况下更改NSDate的日期 - change date of NSDate while keeping the time same 将时间添加到日期选择器的日期和时间将导致相同的日期和时间。 迅速 - Adding time to date picker date and time results in same date and time. SWIFT 是否可以同时构建Fabric和AppStore? - Is it possible to have Fabric and AppStore builds at the same time? 除了使用 Date() ios 之外,还有什么方法可以设置日期时间 - Is there any way to have Date time other than using Date() ios 所有用户的平均停留时间如何大于“桌面和平板电脑”或“平板电脑”用户的平均页面停留时间? - How can the average time for all users be greater than either the average time on page for ‘Desktop and Tablet’ or the ‘Tablet’ users? Swift 3 Firebase-从ID数组返回所有具有ID的用户 - Swift 3 Firebase - Return All Users That Have An ID From An Array of IDs
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM