101618/how-to-get-the-current-date-time-in-java
It depends on what form of date/time you want:
If you want the date/time as a single numeric value, then System.currentTimeMillis() gives you that, expressed as the number of milliseconds after the UNIX epoch (as a Java long). This value is a delta from a UTC time-point and is independent of the local time-zone ... assuming that the system clock has been set correctly.
If you want the date/time in a form that allows you to access the components (year, month, etc) numerically, you could use one of the following:
new Date() gives you a Date object initialized with the current date/time. The problem is that the Date API methods are mostly flawed ... and deprecated.
Calendar.getInstance() gives you a Calendar object initialized with the current date/time, using the default Locale and TimeZone. Other overloads allow you to use a specific Locale and/or TimeZone. The calendar works ... but the APIs are still cumbersome.
new org.joda.time.DateTime() gives you a Joda-time object initialized with the current date/time, using the default time zone and chronology. There are lots of other Joda alternatives ... too many to describe here. (But note that some people report that Joda time has performance issues.; e.g. Jodatime's LocalDateTime is slow when used the first time.)
in Java 8, calling java.time.LocalDateTime.now() and java.time.ZonedDateTime.now() will give you representations1 for the current date / time.
If you require a time stamp in ...READ MORE
Hello, Using java.nio.file.Path and java.nio.file.Paths, you can do the following to ...READ MORE
Using the code below, I attempted to& ...READ MORE
public String getCurrentTimeStamp() { ...READ MORE
This definitely returns UTC time: as String ...READ MORE
This is also a way to work ...READ MORE
import java.time.LocalDate; public class DateIncrementer { static ...READ MORE
We can also use java.util.concurrent.TimeUnit class. long diff = d2.getTime() ...READ MORE
Hi @Daisy You can use Google gson for more ...READ MORE
You can also have a look here: To ...READ MORE
OR
At least 1 upper-case and 1 lower-case letter
Minimum 8 characters and Maximum 50 characters
Already have an account? Sign in.