如何根据用户的本地时区向用户显示保存在数据库中的时间和日期?请查看详细信息 [英] How to show the time and date saved in my database to the user according to their local timezone? Please see details

查看:111
本文介绍了如何根据用户的本地时区向用户显示保存在数据库中的时间和日期?请查看详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,其中我将日期和时间保存在 Firebase 中,然后将其检索给用户查看。

I'm developing an app in which I'm saving the date and time in Firebase and then retrieving it for the user to see.

我想要的是我希望用户根据其本地时区看到该时间和日期。例如-如果数据库中保存的时间和日期为 2:07 PM和 6月24日星期五,那么对于PST时区的用户,应显示为 1:37 AM和 6月6日星期五 24'。

What I want is I want user to see that time and date according to their local timezone. for ex - if the time and date saved in database is '2:07 PM' and 'Fri, Jun 24', then to the users in PST timezone, it should be shown as '1:37 AM' and 'Fri, Jun 24'.

这是我获取时间和日期的方式:

Here's how I'm getting time and date:

        DateFormat currentTime = new SimpleDateFormat("h:mm a");
        final String time = currentTime.format(Calendar.getInstance().getTime());

        DateFormat currentDate = new SimpleDateFormat("EEE, MMM d");
        final String date = currentDate.format(Calendar.getInstance().getTime());

我该如何实现?

请让我知道。

推荐答案

尝试一下:

SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getDefault());
Date myDate = simpleDateFormat.parse("DateAndTimeToBeProcessed");

这篇关于如何根据用户的本地时区向用户显示保存在数据库中的时间和日期?请查看详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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