0

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.

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());

How can I achieve this?

Please let me know.

Hammad Nasir
  • 2,889
  • 7
  • 52
  • 133

1 Answers1

1

Try this:

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