I am developing an app in android in there will be users posting posts from different countries.I want to know how user will get to know the time at which they upload a post to the app. I want to get their local time using my app.
-
I get it the post are saved online, right? In this case, the best way is to use the server date and time, because this way it will be centralized. When you will display date and time, you'll just apply the correct timezone, starting from server's timezone – Gregorio Palamà Jan 17 '19 at 16:41
4 Answers
Well, if you have any centralized database system to save all data related to posts, you can specifically save time in UTC. When displaying you can convert it according to each and every timezone.

- 326
- 3
- 9
-
you mean converting the stored timestamp time to user local time in android studio , right ? – Rahmat Ullah Jan 17 '19 at 16:42
-
Not really. You need to get users timezone first and then convert saved UTC time accordingly when you want to show it on your mobile application. – WMG Jan 17 '19 at 16:54
-
Please refer to this answer for multiple different ways of getting a users current date and time. These times can then be freely converted between timezones, allowing you to store them in some specfic time such as UTC and display them in a users local time.

- 564
- 3
- 11
I think the only solution is to follow these steps:
- Use GPS Location in Android
- Get the user position
- Find the timezone of the place where the user is writing from.
Please do check out the documentation at the following link: https://developer.android.com/guide/topics/location/strategies

- 835
- 1
- 7
- 21
Ordinarily, this chore is simply done for you, according to the user's own preferences as set on the phone. (Commonly called a "locale.")
The resulting date/time value is a number that, IIRC, basically is "UTC." It's an absolute value.
If someone else displays that value on their phone, they will see it expressed in whatever time-zone they've specified for their phone. The "moment in time" will be the same moment.

- 8,490
- 5
- 28
- 41
-
u mean if show the timstamp stored on my sql db in my device using android studio, it will show user local time regardless wherever country they are using from? – Rahmat Ullah Jan 17 '19 at 16:47