Example usage for java.time LocalDate now

List of usage examples for java.time LocalDate now

Introduction

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

Prototype

public static LocalDate now() 

Source Link

Document

Obtains the current date from the system clock in the default time-zone.

Usage

From source file:Main.java

public static void main(String[] args) {
    Period p = Period.ofDays(12);

    Temporal l = p.addTo(LocalDate.now());
    System.out.println(l);

}

From source file:Main.java

public static void main(String[] args) {
    LocalTime l = LocalTime.now();
    LocalDateTime t = l.atDate(LocalDate.now());
    System.out.println(t);/*from w w w . j  a v  a 2s  .  com*/
}

From source file:Main.java

public static void main(String[] args) {
    OffsetDateTime o = OffsetDateTime.of(LocalDate.now(), LocalTime.NOON, ZoneOffset.UTC);

    System.out.println(o);/*from   w w w  .  j  a  v  a2s. c o  m*/
}

From source file:Main.java

public static void main(String[] args) {
    MonthDay m = MonthDay.now();
    Temporal n = m.adjustInto(LocalDate.now());
    System.out.println(n);/*w w  w.j  a  va 2  s  .  c o m*/

}

From source file:Main.java

public static void main(String[] args) {
    Month m = Month.from(LocalDate.now());

    Chronology n = m.query(TemporalQueries.chronology());
    System.out.println(n);//from www .j  ava  2s . co  m

}

From source file:Main.java

public static void main(String[] args) {
    LocalDate localDate = LocalDate.now();
    System.out.println(localDate);

    LocalTime localTime = LocalTime.now();
    System.out.println(localTime);

    LocalDateTime dateTime = LocalDateTime.now();
    System.out.println(dateTime);

    ZonedDateTime dateTimeWithZone = ZonedDateTime.now();
    System.out.println(dateTimeWithZone);
}

From source file:Main.java

public static void main(String[] args) {
    Period p = Period.ofDays(12);

    Temporal l = p.subtractFrom(LocalDate.now());
    System.out.println(l);/* w  ww . j  a va2 s . c  o m*/

}

From source file:Main.java

public static void main(String[] args) {
    OffsetTime m = OffsetTime.now();
    OffsetDateTime n = m.atDate(LocalDate.now());
    System.out.println(n);/*from w w w  .  j  av  a  2 s .  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) {
    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);
}