It seems to be a wrong question but hear me out. When i call System.currentTimeMillis() it gives me seconds which when I convert to human readable format from an online milliseconds to date converter gives me GMT or UTC time but not my local time. Is there a way to get the current local time in millisec as I see there is a change of millsec value on online converter when I enter my local time in it.
To summarize, my problem is to get the current local time in milliseconds which some how is different from what I get using System.currentTimeMillis() function in java.
To get the current time in milliseconds, you just need to convert the output of Sys. time to numeric, and multiply by 1000.
Using timedelta. A simple solution is to get the timedelta object by finding the difference of the given datetime with Epoch time, i.e., midnight 1 January 1970. To obtain time in milliseconds, you can use the timedelta. total_seconds() * 1000 .
json"(February 26, 2019 12:00:00 AM) and that need to be accessed from android app once device's System. currentTimeMillis() returns exact time.
currentTimeMillis() method returns the current time in milliseconds. The unit of time of the return value is a millisecond, the granularity of the value depends on the underlying operating system and may be larger. For example, many operating systems measure time in units of tens of milliseconds.
You can use TimeZone.getOffset(long)
which gives the amount of time in milliseconds to add to UTC to get local time. Something like,
long date = System.currentTimeMillis();
int offset = TimeZone.getDefault().getOffset(date);
System.out.printf("%d + %d = %d%n", date, offset, date + offset);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With