public static LocalDate of(int year, Month month, int dayOfMonth) Parameters. year − the year to represent, from MIN_YEAR to MAX_YEAR. month − the month-of-year to represent. dayOfMonth − the day-of-month to represent, from 1 to 31. Return Value. the local date, not null. Example. The following example shows the usage of java.time
The Time package is a new date, time, and calendar API for the Java SE platform. The main difference between old legacy Date and is that the new API distinguishes between machine and human views of a timeline. The machine view reveals a sequence of integral values relative to the epoch, whereas view reveals a set of fields (e.g., year or day).
1 Answer. If you want to extract the single values of year, month and day of month from a datetime given in milliseconds, you should nowadays use java.time for that. public static void main (String [] args) { // example millis of "now" long millis = Instant.now ().toEpochMilli (); // use your a.creationDate; here instead // create an Instant
This answer is to introduce the modern Date-Time API to future visitors. java.time. The java.util Date-Time API and their formatting API, SimpleDateFormat are outdated and error-prone. It is recommended to stop using them completely and switch to the modern Date-Time API *. Solution using java.time, the modern Date-Time API:
@GeghamVirabyan - For any reason, if you have to stick to Java 6 or Java 7, you can use ThreeTen-Backport which backports most of the java.time functionality to Java 6 & 7. If you are working for an Android project and your Android API level is still not compliant with Java-8, check Java 8+ APIs available through desugaring .
Xtdld.
java date year month day