package dates; import java.time.LocalDate; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.Month; import java.time.format.DateTimeFormatter; /** * * @author Lefteris Moussiades */ public class Formating { static void dateTimeF() { LocalDate d = LocalDate.of(2015, Month.FEBRUARY, 25); String s=d.format(DateTimeFormatter.ISO_DATE); System.out.println("ISO_DATE "+d.format(DateTimeFormatter.ISO_DATE)); System.out.println("ISO_WEEK_DATE "+d.format(DateTimeFormatter.ISO_WEEK_DATE)); System.out.println("ISO_ORDINAL_DATE "+d.format(DateTimeFormatter.ISO_ORDINAL_DATE)); System.out.println(""); LocalTime t = LocalTime.of(10, 35); System.out.println("ISO_TIME "+t.format(DateTimeFormatter.ISO_TIME)); System.out.println(""); LocalDateTime dt = LocalDateTime.of(2015, Month.JANUARY, 25, 10, 30); System.out.println("ISO_DATE_TIME "+dt.format(DateTimeFormatter.ISO_DATE_TIME)); System.out.println("ISO_WEEK_DATE "+dt.format(DateTimeFormatter.ISO_WEEK_DATE)); System.out.println("ISO_ORDINAL_DATE "+dt.format(DateTimeFormatter.ISO_ORDINAL_DATE)); System.out.println("ISO_DATE "+dt.format(DateTimeFormatter.ISO_DATE)); System.out.println("ISO_TIME "+dt.format(DateTimeFormatter.ISO_TIME)); } static void patternFormatting() { LocalDate d = LocalDate.of(2015, Month.FEBRUARY, 25); System.out.println("yyyy/MM/dd "+d.format(DateTimeFormatter.ofPattern("yyyy/MM/dd"))); System.out.println("dd/MM/yyyy "+d.format(DateTimeFormatter.ofPattern("dd/MM/yyyy"))); System.out.println("dd/MM/yy "+d.format(DateTimeFormatter.ofPattern("dd/MM/yy"))); System.out.println("dd/MMM/yy "+d.format(DateTimeFormatter.ofPattern("dd/MMM/yy"))); System.out.println("yyyy "+d.format(DateTimeFormatter.ofPattern("yyyy"))); System.out.println("dd.MM.yy "+d.format(DateTimeFormatter.ofPattern("dd.MM.yy"))); System.out.println(""); LocalTime t = LocalTime.of(16, 35); System.out.println("hh:mm:ss " +t.format(DateTimeFormatter.ofPattern("hh:mm:ss a"))); System.out.println("HH:mm:ss " +t.format(DateTimeFormatter.ofPattern("HH:mm:ss"))); System.out.println(""); LocalTime t1 = LocalTime.of(4, 35); System.out.println("hh:mm:ss " +t1.format(DateTimeFormatter.ofPattern("hh:mm:ss a"))); System.out.println("HH:mm:ss " +t1.format(DateTimeFormatter.ofPattern("HH:mm:ss"))); System.out.println(""); LocalDateTime dt = LocalDateTime.of(2015, Month.JANUARY, 25, 10, 30); System.out.println("dd.MM.yy,hh:mm:ss "+dt.format(DateTimeFormatter.ofPattern("dd.MM.yy,hh:mm:ss"))); System.out.println("dd.MM.yy hh.mm.ss "+dt.format(DateTimeFormatter.ofPattern("dd.MM.yy hh.mm.ss"))); } public static void main(String[] args) { //dateTimeF(); patternFormatting(); } }