如何根据本地正确显示Firestore serverTimestamp [英] How to show Firestore serverTimestamp correctly depending on local

查看:92
本文介绍了如何根据本地正确显示Firestore serverTimestamp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法正确解决此问题,并且想知道如何根据设备具有的local来显示Firestore FieldValue.serverTimestamp()格式个体.

I cant get this right and wonder how to show the Firestore FieldValue.serverTimestamp() formatet individual depending on what local the device has.

Firestore timestamp如下

The Firestore timestamp look like this

2018年3月10日星期六19:42:32 GMT + 01:00

Sat Mar 10 19:42:32 GMT+01:00 2018

try {
      SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSS", Locale.getDefault());
        Date parsedDate = dateFormat.parse("Sat Mar 10 19:42:32 GMT+01:00 2018");
        txtCreationDate.setText(new Date(parsedDate.getTime()).toString());
     } catch (ParseException e) {
        txtCreationDate.setText("time error");
     }

如果一个用户(美国)创建了日期时间对象,那么如果另一个用户(意大利)进行了查看,则创建时间必须调整为他的时钟

If one user i USA create the date time object then if another user i Italy view it then the creation time must adjusted to his clock

我已经阅读了很多关于此的页面,但dateFormat解析器仅给我错误.
请指教

I have read many pages about this but the dateFormat parser give me error only.
Please advice

推荐答案

假设您有一个名为MyClass的模型类,该模型类具有一个Date字段以及公共的setter和getter,要获取日期,请使用以下命令代码:

Assuming that you have a model class named MyClass that has a Date field and public setters and getters, to get the date, please use the following code:

Date date = yourClass.getDate();
if (date != null) {
    DateFormat dateFormat = SimpleDateFormat.getDateTimeInstance(DateFormat.FULL, DateFormat.FULL, Locale.getDefault());
    String creationDate = dateFormat.format(date);
    Log.d("TAG", creationDate);
}

这篇关于如何根据本地正确显示Firestore serverTimestamp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆