Wednesday, 9 August 2017

How to get today's Date in java in the following pattern dd/MM/yyyy?

Using java.time.LocalDate,


DateTimeFormatter dtf = DateTimeFormatter.ofPattern("yyyy/MM/dd");
LocalDate localDate = LocalDate.now();
System.out.println(dtf.format(localDate)); //2016/11/16

Use DateTimeFormatter to format the date as you want.


In your case the pattern is "dd/MM/yyyy".


Info ⬇️


Java 8 introduced new APIs for Date and Time to address the shortcomings of the older java.util.Date and java.util.Calendar. The core classes of the new Java 8 project that are part of the java.time package like LocalDate, LocalTime, LocalDateTime, ZonedDateTime, Period, Duration and their supported APIs.


The LocalDate provides various utility methods to obtain a variety of information. For example:


1) The following code snippet gets the current local date and adds one day:


LocalDate tomorrow = LocalDate.now().plusDays(1);

2) This example obtains the current date and subtracts one month. Note how it accepts an enum as the time unit:


LocalDate previousMonthSameDay = LocalDate.now().minus(1, ChronoUnit.MONTHS);

No comments:

Post a Comment

casting - Why wasn't Tobey Maguire in The Amazing Spider-Man? - Movies & TV

In the Spider-Man franchise, Tobey Maguire is an outstanding performer as a Spider-Man and also reprised his role in the sequels Spider-Man...