Rahmat Ullah
Rahmat Ullah

Reputation: 229

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

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.

Upvotes: 0

Views: 931

Answers (4)

Mike Robinson
Mike Robinson

Reputation: 8945

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.

Upvotes: 0

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

Upvotes: 0

B. Plüster
B. Plüster

Reputation: 654

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.

Upvotes: 0

WMG
WMG

Reputation: 336

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.

Upvotes: 1

Related Questions