简体   繁体   English

需要将UTC时间转换为设备的当前时区

[英]need to convert UTC time to current timezone of device

Im using this repo 我正在使用这个仓库

https://github.com/remirobert/Tempo https://github.com/remirobert/Tempo

Can someone help me understand how to grab the current time zone of the device, and then notify tempo? 有人可以帮助我了解如何获取设备的当前时区,然后通知速度吗? I am using the timeAgoNow() function of tempo to find display how long ago the post was made, but the timezone difference is messing it up. 我正在使用tempo的timeAgoNow()函数来查找显示发布该帖子的时间,但是时区差将其弄乱了。 My datasource is using UTC time. 我的数据源正在使用UTC时间。

Cocoa uses UTC internally. 可可在内部使用UTC。 for all of its date/time calculations. 用于其所有日期/时间计算。

If you create an NSDate for now: 如果您现在创建NSDate:

NSDate() NSDate()

You get a date that is the number of elapsed seconds since midnight, 1970 in UTC time. 您获得的日期是从UTC时间到1970年午夜以来经过的秒数。

Dates only have time zones when you display them. 日期仅在显示时区。

By default logging a date to the console logs it in UTC, which can be confusing. 默认情况下,将日期记录到控制台会将其记录为UTC,这可能会造成混淆。

If I'm working on a project that does a lot of date/time calculations I'll create a debugging method that converts an NSDate to a date/time string in the current locale, which is easier to read/debug without having to mentally convert from UTC back to local time. 如果我正在进行大量日期/时间计算的项目,则将创建一个调试方法,该方法将NSDate转换为当前语言环境中的日期/时间字符串,这样更易​​于阅读/调试,而无需费心从UTC转换回当地时间。

I have never used Tempo, so I don't know if it is using date strings, NSDate, or "internet dates" (which are also in UTC, but use a different "zero date" or "epoch date") 我从未使用过Tempo,所以我不知道它是否使用日期字符串,NSDate或“互联网日期”(这也是UTC,但使用不同的“零日期”或“时代”))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UTC-5时区日期和时间iPhone应用程序获取当前iPhone设备的时区日期和时间? - Get current iPhone device timezone date and time from UTC-5 timezone date and time iPhone app? 无法转换UTC时间 - Not able to convert UTC time 将UTC时间转换为当前时区时间时转换为错误时间 - Convert into wrong time while converting UTC time to current time zone time iOS:将 UTC NSDate 转换为本地时区 - iOS: Convert UTC NSDate to local Timezone Swift UTC 时区不是 UTC - Swift UTC TimeZone is not UTC 如何在Swift中以“Hours:Minutes AM/PM”格式将“Hours:Minutes:Seconds AM/PM”(UTC时区)转换为用户的时区? - How to convert "Hours:Minutes:Seconds AM/PM"(UTC timezone) to the user's time zone in the format of "Hours:Minutes AM/PM" in Swift? 从 UTC 转换为本地时区给出错误的结果 - Convert from UTC to local timezone give wrong result 将日期字符串表示为UTC日期并将其转换为本地时区 - Represent date string as UTC date and convert it into local timezone 如何在Swift 3中将UTC时间转换为当地时间? - How to Convert UTC time to local time In Swift 3? Catalyst datePicker 显示系统时间而不是 utc 时间(datePicker 时区已设置为 UTC) - Catalyst datePicker shows system time instead of utc time (the datePicker timezone has been set to UTC)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM