How to get date and time for different users in different countries in android?

897 views Asked by At

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.

4

There are 4 answers

3
WMG On

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.

0
B. Plüster On

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.

0
Eminent Emperor Penguin On

I think the only solution is to follow these steps:

  1. Use GPS Location in Android
  2. Get the user position
  3. 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

1
Mike Robinson On

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.