Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios Firebase&;Swift-使用UTC-7保存的日期?_Ios_Swift_Firebase_Google Cloud Firestore - Fatal编程技术网

Ios Firebase&;Swift-使用UTC-7保存的日期?

Ios Firebase&;Swift-使用UTC-7保存的日期?,ios,swift,firebase,google-cloud-firestore,Ios,Swift,Firebase,Google Cloud Firestore,我想了解Firebase的CloudFirestore中的日期是如何准确保存的 当我将当前日期放入数据库dateToSAve=date()时,该日期与UTC-7一起存储: 但在法国,如果有人想在Firebase上保存数据,则当前日期为9小时,以符合UTC-7 有时候,正因为如此,今天可能会是不同的一天。。。 你知道如何处理这个问题吗?我想在数据库中保存用户的当前日期。您不应该在数据库中存储日期对象,而应该在UTC 0中保存时间戳。在检索到时间戳之后,您可以将其转换回当前时区中具有时间部分的日期

我想了解Firebase的CloudFirestore中的日期是如何准确保存的

当我将当前日期放入数据库
dateToSAve=date()
时,该日期与UTC-7一起存储:

但在法国,如果有人想在Firebase上保存数据,则当前日期为9小时,以符合UTC-7

有时候,正因为如此,今天可能会是不同的一天。。。
你知道如何处理这个问题吗?我想在数据库中保存用户的当前日期。

您不应该在数据库中存储日期对象,而应该在UTC 0中保存时间戳。在检索到时间戳之后,您可以将其转换回当前时区中具有时间部分的日期

要获取UTC 0中的时间戳:

let timestamp = Date().timeIntervalSince1970
以及将时间戳转换回当前时区的时间部分:

// gives date with time portion in UTC 0
let date = Date(timeIntervalSince1970: timestamp)

let dateFormatter = DateFormatter()
dateFormatter.dateFormat = "MMM-dd-yyyy"  // change to your required format
dateFormatter.timeZone = TimeZone.current

// date with time portion in your specified timezone
print(dateFormatter.string(from: date))