Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/firebase/6.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
android vs firebase函数中的Firestore时间戳格式_Firebase_Google Cloud Firestore_Google Cloud Functions - Fatal编程技术网

android vs firebase函数中的Firestore时间戳格式

android vs firebase函数中的Firestore时间戳格式,firebase,google-cloud-firestore,google-cloud-functions,Firebase,Google Cloud Firestore,Google Cloud Functions,在我的平台中,firestore时间戳处于 t:2020年4月7日中午12:07:16 UTC+5:30 由android客户端使用以下代码创建: createdAt = new Timestamp(new Date()); 试图从firebase cloud函数内部创建上述日期格式,但它以以下格式返回日期 t:2020-04-07T20:35:08.717Z 使用代码 t: new Date().toISOString() 也试过 Firestore.Timestamp.now(); 有

在我的平台中,firestore时间戳处于

t:2020年4月7日中午12:07:16 UTC+5:30

由android客户端使用以下代码创建:

createdAt = new Timestamp(new Date());
试图从firebase cloud函数内部创建上述日期格式,但它以以下格式返回日期

t:2020-04-07T20:35:08.717Z

使用代码

t: new Date().toISOString()
也试过

Firestore.Timestamp.now();
有没有人能帮助我们以android中的相同格式获取日期

精确代码是云函数中的对象填充,并以上述不兼容的格式返回时间

let messagePayload = {
          msg:"A test message",
          mt:"text",
          pm:"",
          pmdi:"",
          sb:"1908392XXXX",
          sdi:"Ichthyocentaurs",
          t: new Date().toISOString() 
        }

您在Android上看到的格式非常特定于设备配置为运行的区域设置,这取决于语言和时区。此默认字符串格式通常不应用于调试目的以外的任何用途

您在JavaScript中看到的格式旨在传输格式化为字符串的日期,以便在系统之间共享,而不是用于显示

如果您想在JavaScript中使用特定的日期格式,我强烈建议您使用一些库或实用程序,以可预测的方式将日期和时间格式化为您认为合适的格式。JavaScript没有内置任何良好的日期格式化功能。相反,请考虑使用一些类似的方法来精确地指定所需的字符串格式。 对于您的具体情况,如果您试图向android客户端应用程序发送日期,我也强烈建议您不要在后端格式化,而是使用android平台内置的日期格式化实用程序,例如。默认的Java日期字符串格式几乎肯定不是您想要的格式。您将能够使用Android设备上提供的区域设置格式化日期,这是用户根据其设置可能更喜欢的