How to get current time-stamp in UTC/GMT and then How to convert this time-stamp into seconds ? Itry this but its thrw exception
SimpleDateFormat sdfu = new SimpleDateFormat("yyyy-MM-dd kk:mm");
Date udate = sdfu.parse(dateAndTimeUTC);
long timeInMillisSinceEpoch123 = udate.getTime();
long durationinSeconds2 = timeInMillisSinceEpoch123 / 1000;
System.out.println("Time in Seconds UTC: " + durationinSeconds2);
Is there any better way to convert UTC/GMT time-stamp into seconds?
Current UTC timestamp to time is 13:56:19.
getTime(); long durationinSeconds2 = timeInMillisSinceEpoch123 / 1000; System. out. println("Time in Seconds UTC: " + durationinSeconds2);
Use the getTime() method to get a UTC timestamp, e.g. new Date(). getTime() . The method returns the number of milliseconds since the Unix Epoch and always uses UTC for time representation. Calling the method from any time zone returns the same UTC timestamp.
Getting the UTC timestamp Use the datetime. datetime. now() to get the current date and time. Then use tzinfo class to convert our datetime to UTC.
With Java 8+, you can use:
Instant.now().getEpochSecond()
get current seconds system
long timestamp = System.currentTimeMillis() / 1000;
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