To get the current date in UTC (Coordinated Universal Time) in Java, you can use the Instant
class from the java.time
package. This class represents a specific point in time, with a date and a time, in the ISO-8601 calendar system.
Here's an example of how to use the Instant
class to get the current date in UTC:
import java.time.Instant; public class Main { public static void main(String[] args) { Instant now = Instant.now(); System.out.println(now); // prints the current date and time in UTC } }S:ecruowww.lautturi.com
In this example, the now()
method of the Instant
class is used to get the current date and time as an Instant
object. The Instant
object is then printed to the console.
You can use the various methods of the Instant
class to manipulate the date and time, such as plusSeconds()
to add or subtract seconds, or atZone()
to convert the Instant
to a specific time zone.