Example usage for java.time LocalDate format

List of usage examples for java.time LocalDate format

Introduction

In this page you can find the example usage for java.time LocalDate format.

Prototype

@Override 
public String format(DateTimeFormatter formatter) 

Source Link

Document

Formats this date using the specified formatter.

Usage

From source file:Main.java

public static void main(String[] args) {
    LocalDate a = LocalDate.of(2014, 6, 30);

    String s = a.format(DateTimeFormatter.BASIC_ISO_DATE);

    System.out.println(s);//from  w  w  w .j a  va2s . c  o  m
}

From source file:Main.java

public static void main(String[] argv) {
    LocalDate ld = LocalDate.now();
    String ldStr = ld.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Local  Date: " + ldStr);

    OffsetDateTime odt = OffsetDateTime.now();
    String odtStr = odt.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Offset  Datetime: " + odtStr);

    ZonedDateTime zdt = ZonedDateTime.now();
    String zdtStr = zdt.format(DateTimeFormatter.ISO_DATE);
    System.out.println("Zoned  Datetime: " + zdtStr);
}

From source file:Main.java

public static void main(String[] args) {
    DateTimeFormatter formatter = new DateTimeFormatterBuilder().appendLiteral("New Year in ")
            .appendValue(ChronoField.YEAR).appendLiteral(" is  on  ")
            .appendText(ChronoField.DAY_OF_WEEK, TextStyle.FULL_STANDALONE).toFormatter();
    LocalDate ld = LocalDate.of(2014, Month.JANUARY, 1);
    String str = ld.format(formatter);
    System.out.println(str);//from  w ww .j  a  va 2  s  .  c o  m

}

From source file:Main.java

public static void main(String[] args) {
    Instant instant = Instant.parse("2014-07-16T10:15:30.00Z");
    LocalDate localDate = LocalDate.parse("2014-07-16", DateTimeFormatter.ofPattern("yyyy-MM-dd"));
    LocalDate localDate2 = LocalDate.parse("2014-07-16", DateTimeFormatter.ISO_LOCAL_DATE);

    DateTimeFormatter strangeFormat = new DateTimeFormatterBuilder().appendValue(MONTH_OF_YEAR, 2)
            .appendLiteral("==").appendValue(YEAR, 4).appendLiteral("--").appendValue(DAY_OF_MONTH, 2)
            .toFormatter();//  w w w.ja v a  2  s . c o m

    LocalDate localDate3 = LocalDate.parse("07==2014--16", strangeFormat);

    System.out.println(instant);
    System.out.println(localDate);
    System.out.println(localDate2);
    System.out.println(localDate3);

    LocalDate date = Year.of(2014).atMonth(7).atDay(16);
    String strangeDateFormat = date.format(strangeFormat);

    System.out.println(strangeDateFormat);
}

From source file:Main.java

public static void main(String[] args) {
    LocalDate ld = LocalDate.of(2014, Month.JANUARY, 1);
    String pattern = "'New Year in'  yyyy  'is on' EEEE";
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern(pattern);
    String str = ld.format(formatter);
    System.out.println(str);//from www.  j a  va  2s .  c  o  m

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate date = LocalDate.now();
    // default format
    System.out.println("Default format of LocalDate=" + date);
    // specific format
    System.out.println(date.format(DateTimeFormatter.ofPattern("d::MMM::uuuu")));
    System.out.println(date.format(DateTimeFormatter.BASIC_ISO_DATE));

    LocalDateTime dateTime = LocalDateTime.now();
    // default format
    System.out.println("Default format of LocalDateTime=" + dateTime);
    // specific format
    System.out.println(dateTime.format(DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss")));
    System.out.println(dateTime.format(DateTimeFormatter.BASIC_ISO_DATE));

    Instant timestamp = Instant.now();
    // default format
    System.out.println("Default format of Instant=" + timestamp);

    // Parse examples
    LocalDateTime dt = LocalDateTime.parse("27::Apr::2014 21::39::48",
            DateTimeFormatter.ofPattern("d::MMM::uuuu HH::mm::ss"));
    System.out.println("Default format after parsing = " + dt);
}

From source file:Main.java

public static void main(String[] args) {
    Month month = null;/*from  ww  w .ja va  2s. co  m*/
    LocalDate date = null;
    DateTimeFormatter format;
    String out = null;

    month = Month.valueOf("May".toUpperCase());
    date = Year.now().atMonth(month).atDay(12);

    LocalDate nextPayday = date.with(new PaydayAdjuster());

    format = DateTimeFormatter.ofPattern("yyyy MMM d");
    out = date.format(format);
    System.out.printf("Given the date:  %s%n", out);
    out = nextPayday.format(format);
    System.out.printf("the next payday: %s%n", out);
}

From source file:Main.java

public static String toUUUUMM(LocalDate localDate) {
    return localDate.format(DateTimeFormatter.ofPattern("uuuuMM"));
}

From source file:Main.java

public static String toString(LocalDate date) {
    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd/MM/yyyy");
    return date.format(formatter);
}

From source file:edu.psu.swe.scim.spec.protocol.filter.AttributeComparisonExpression.java

public static String toDateString(LocalDate ld) {
    return ld.format(DateTimeFormatter.ISO_DATE);
}