0

In my project I use timestamp to work with dates. Since there can be different times everywhere, I need to get a timestamp from the selected city.

For example, I need to get a timestamp from the city of Paris. How can I do it?

P.S.: minSdkVersion 23

onesector
  • 361
  • 5
  • 18
  • Can you clarify what you mean by time stamp? A Long representing UTC offset to the local time zone? A ZonedDateTime instance? A String with a formatted date? etc.? – Tenfour04 Nov 17 '22 at 20:13
  • @Tenfour04 Long data type – onesector Nov 17 '22 at 20:14
  • Still not clear. A long of what? Milliseconds since the epoch, but offset by the timezone from UTC? If the timestamp is just UTC time, then the timezone is irrelevant, unless the input is a local time and a city. There's not enough info about your specific inputs and outputs to answer this. – Tenfour04 Nov 17 '22 at 20:21
  • @Tenfour04 Let's say I need to get the current time in London, but I'm in a completely different place with a completely different time. However, regardless of my location, I must get timestamp of the city I have chosen (in this case, London). On the output, I should get the time in milliseconds – onesector Nov 17 '22 at 20:32
  • But time in ms since when? It's simplest to just use milliseconds since the epoch (UTC time) so time zone is irrelevant. It has been the same number of ms since the epoch no matter where you are. – Tenfour04 Nov 17 '22 at 20:41
  • @Tenfour04 Ok, I can use UTC, then how can this be done? – onesector Nov 17 '22 at 20:44
  • That's just `System.currentTimeMillis()` – Tenfour04 Nov 17 '22 at 20:46
  • @Tenfour04 It's just that there is such a problem that I used this method, and it always depends on what time is currently used in the system. And if the user moves the clock, then it will not work correctly. – onesector Nov 17 '22 at 20:51
  • Only way to avoid that is to connect to a remote server that has the accurate time. See here https://stackoverflow.com/questions/31529484/get-accurate-utc-time-in-android – Tenfour04 Nov 17 '22 at 20:55

0 Answers0