There are many threads on retreiving pacific time from servers but i want to convert it into the local time like IST. I am living in India. Prefferably i want to use firebase for retreiving time . If you can provide me with a code that retreives time fron firebase and convert it into the local time and date , i will be very thankful.
Asked
Active
Viewed 2,872 times
3 Answers
1
- You have to get time from server, They are lot of services but I prefer to use this one which gives you all data you need in
UTCtimezone: https://script.google.com/macros/s/AKfycbyd5AcbAnWi2Yn0xhFRbyzS4qMq1VucMVgVvhul5XqS9HkAyJY/exec (from http://davidayala.eu/current-time) - Then You have to Parse the service response and Get the Values you need.
- Finally Instantiate Calendar and Set it with the value you got (day, week, month) and get the time in the timezone you want with the format you want ^^
P.S: You can also get the time in any timezone (It support many local time in India too) from the above API without any need for conversion.
Keivan Esbati
- 3,113
- 1
- 20
- 36
-
Your welcome, well each step may need a little time and effort to implement. Let me know if this is working for you ^^ – Keivan Esbati Mar 10 '17 at 08:02
0
- get the time (time milliseconds) from internet server .(You can attach it response from the server ).
get the zone of the internet server let it be +2:45 ( also attach it in response from server ) and convert it to milliseconds.
get the timezone (+6:00) from your device and convert it to milliseconds.
4.now to the time milliseconds from the server add the following (time milliseconds from server +your timezone milliseconds - server timezone milliseconds
- now convert result to your desired time date format
erluxman
- 15,908
- 19
- 82
- 111
-
@AbhinavMarwaha at least do Google and also thank person for providing answer with details. – Paresh Mayani Mar 08 '17 at 05:05
-
Sorry for that i will google it and i am still learning from all the great developers out there . Thank you for your help . I am still wondering why my question is downvoted atleast provide me with reason so that i can improve. Thank you once again.@PareshMayani – Abhinav Marwaha Mar 08 '17 at 05:13
0
set your time zone to calendar and simply get DAY, Minute, Hour, DAY, WEEK etc.
TimeZone tz = TimeZone.getTimeZone("GMT+05:30");
Calendar c = Calendar.getInstance(tz);
String time = String.format("%02d" , c.get(Calendar.HOUR_OF_DAY))+":"+
String.format("%02d" , c.get(Calendar.MINUTE))+":"+
String.format("%02d" , c.get(Calendar.SECOND))+":"+
String.format("%03d" , c.get(Calendar.MILLISECOND));
Reference : Get current time in a given timezone : android
Community
- 1
- 1
Jitesh Prajapati
- 2,661
- 4
- 28
- 47