我正在开发一个应用,我在Firebase
中保存日期和时间,然后检索它以供用户查看。
我想要的是我希望用户根据当地时区查看时间和日期。例如 - 如果保存在数据库中的时间和日期是' 2:07 PM'然后,对于PST时区的用户,它应该显示为' 1:37 AM'' Fri,Jun 24'和'星期五,6月24日'。
以下是我如何获得时间和日期:
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());
我怎样才能做到这一点?
请告诉我。
答案 0 :(得分:0)
试试这个:
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
simpleDateFormat.setTimeZone(TimeZone.getDefault());
Date myDate = simpleDateFormat.parse("DateAndTimeToBeProcessed");