-4

I am making a real-time tracking app. I have added a few users who are in 2 different time zones. I am trying to fetch the last time and date they were online, so far I have been able to fetch date and time, however, it is showing me time online in their country, I'd like to get the time converted based on my time zone.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    Please be a bit more specific when asking a question: *What have you tried so far with a code example? ([I downvoted because there is no code](http://idownvotedbecau.se/nocode/))* / *What do you expect?* / *What error do you get?* **For Help take a look at "[How to ask](https://stackoverflow.com/help/how-to-ask)"** – Hille Jan 04 '18 at 14:18
  • Welcome to StackOverflow. Please use [this guide on How To Ask](https://stackoverflow.com/help/how-to-ask) to avoid negative feedback and clarify your question. Provide code samples and your attempts on how you tried to solve the problem. – creyD Jan 04 '18 at 14:19
  • The same question was asked today [Timezone Conversion](https://stackoverflow.com/questions/48093211/get-local-time-zone-on-android-without-sim#comment83160874_48093211) – Nick Cardoso Jan 04 '18 at 15:01
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Jan 05 '18 at 09:21

1 Answers1

0

You need to know in which GMT is their last updated time and then convert it into your GMT time. However it will be more simple if you make user to update their local time in your GMT.

public void timeZoneConverter() {

 //Date will return local time in 

 Date localTime = new Date(); 

 //creating DateFormat for converting time from local timezone to GMT

 DateFormat converter = new SimpleDateFormat("dd/MM/yyyy:HH:mm:ss");

 //getting GMT timezone, you can get any timezone e.g. UTC

 converter.setTimeZone(TimeZone.getTimeZone("GMT"));

 System.out.println("Local time : " + localTime);;
 System.out.println("Time in GMT : " + converter.format(localTime));
}
iamnaran
  • 1,894
  • 2
  • 15
  • 24