List of usage examples for java.time LocalTime now
public static LocalTime now()
From source file:Main.java
public static void main(String[] args) { LocalDate date = LocalDate.now(); LocalTime time = LocalTime.now(); LocalDateTime dateTimeFromDateAndTime = LocalDateTime.of(date, time); System.out.println(dateTimeFromDateAndTime); LocalDate dateFromDateTime = LocalDateTime.now().toLocalDate(); LocalTime timeFromDateTime = LocalDateTime.now().toLocalTime(); System.out.println(dateFromDateTime); System.out.println(timeFromDateTime); }
From source file:Main.java
public static void main(String[] args) { ZonedDateTime z = ZonedDateTime.of(LocalDate.now(), LocalTime.now(), ZoneId.systemDefault()); System.out.println(z);//from w ww . j av a2s . co m }
From source file:Main.java
public static void main(String[] args) { LocalTime d = LocalTime.now(); System.out.println(toDate(d)); }
From source file:Main.java
public static void main(String[] args) { LocalTime now = LocalTime.now(); LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles")); System.out.println(String.format("now is %s and in LA is %s", now, currentTimeInLosAngeles)); ZoneId leavingZone = ZoneId.of("Asia/Tel_Aviv"); ZoneId arrivingZone = ZoneId.of("America/New_York"); LocalDateTime leaving = LocalDateTime.of(2014, Month.JULY, 16, 23, 00); ZonedDateTime departure = ZonedDateTime.of(leaving, leavingZone); ZonedDateTime arrival = departure.withZoneSameInstant(arrivingZone).plusHours(11).plusMinutes(51); DateTimeFormatter format = DateTimeFormatter.ofPattern("yyyy-MM-d HH:mm"); System.out.println(String.format("Departure: %s", departure.format(format))); System.out.println(String.format("Arrival: %s", arrival.format(format))); }
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) { TemporalQuery<TemporalUnit> precision = TemporalQueries.precision(); System.out.println(LocalDate.now().query(precision)); // Days System.out.println(LocalTime.now().query(precision)); // Nanos System.out.println(YearMonth.now().query(precision)); // Months }
From source file:Main.java
public static void main(String[] args) { LocalDate today = LocalDate.now(); // Get the Year, check if it's leap year System.out.println("Year " + today.getYear() + " is Leap Year? " + today.isLeapYear()); // Compare two LocalDate for before and after System.out.println("Today is before 01/01/2015? " + today.isBefore(LocalDate.of(2015, 1, 1))); // Create LocalDateTime from LocalDate System.out.println("Current Time=" + today.atTime(LocalTime.now())); }
From source file:Main.java
public static void main(String[] args) { LocalDate february20th = LocalDate.of(2014, Month.FEBRUARY, 20); System.out.println(february20th); System.out.println(LocalDate.from(february20th.plus(15, ChronoUnit.YEARS))); // 2029-02-20 System.out.println(LocalDate.MAX); System.out.println(LocalDate.MIN); System.out.println(LocalTime.MIDNIGHT); // 00:00 System.out.println(LocalTime.NOON); // 12:00 System.out.println(LocalTime.of(23, 12, 30, 500)); // 23:12:30.000000500 System.out.println(LocalTime.now()); // 00:40:34.110 System.out.println(LocalTime.ofSecondOfDay(11 * 60 * 60)); // 11:00 System.out.println(LocalTime.from(LocalTime.MIDNIGHT.plusHours(4))); // 04:00 System.out.println(LocalTime.MIN); System.out.println(LocalTime.MAX); System.out.println(LocalDateTime.of(2014, 2, 15, 12, 30, 50, 200)); // 2014-02-15T12:30:50.000000200 System.out.println(LocalDateTime.now()); // 2014-02-28T17:28:21.002 System.out.println(LocalDateTime.from(LocalDateTime.of(2014, 2, 15, 12, 30, 40, 500).plusHours(19))); // 2014-02-16T07:30:40.000000500 System.out.println(LocalDateTime.MAX); }
From source file:Main.java
public static void main(String[] args) { // the current date LocalDate currentDate = LocalDate.now(); // 2014-02-10 LocalDate tenthFeb2014 = LocalDate.of(2014, Month.FEBRUARY, 10); // months values start at 1 (2014-08-01) LocalDate firstAug2014 = LocalDate.of(2014, 8, 1); // the 65th day of 2010 (2010-03-06) LocalDate sixtyFifthDayOf2010 = LocalDate.ofYearDay(2010, 65); // times, e.g. 19:12:30.733 LocalTime currentTime = LocalTime.now(); // current time LocalTime midday = LocalTime.of(12, 0); // 12:00 LocalTime afterMidday = LocalTime.of(13, 30, 15); // 13:30:15 // 12345th second of day (03:25:45) LocalTime fromSecondsOfDay = LocalTime.ofSecondOfDay(12345); // dates with times, e.g. 2014-02-18T19:08:37.950 LocalDateTime currentDateTime = LocalDateTime.now(); // 2014-10-02 12:30 LocalDateTime secondAug2014 = LocalDateTime.of(2014, 10, 2, 12, 30); // 2014-12-24 12:00 LocalDateTime christmas2014 = LocalDateTime.of(2014, Month.DECEMBER, 24, 12, 0); // current (local) time in Los Angeles LocalTime currentTimeInLosAngeles = LocalTime.now(ZoneId.of("America/Los_Angeles")); // current time in UTC time zone LocalTime nowInUtc = LocalTime.now(Clock.systemUTC()); System.out.println("date/time creation: currentDate: " + currentDate); System.out.println("date/time creation: tenthFeb2014: " + tenthFeb2014); System.out.println("date/time creation: firstAug2014: " + firstAug2014); System.out.println("date/time creation: sixtyFifthDayOf2010: " + sixtyFifthDayOf2010); System.out.println("date/time creation: currentTime: " + currentTime); System.out.println("date/time creation: midday: " + midday); System.out.println("date/time creation: afterMidday: " + afterMidday); System.out.println("date/time creation: fromSecondsOfDay: " + fromSecondsOfDay); System.out.println("date/time creation: currentTimeInLosAngeles: " + currentTimeInLosAngeles); System.out.println("date/time creation: currentDateTime: " + currentDateTime); System.out.println("date/time creation: secondAug2014: " + secondAug2014); System.out.println("date/time creation: christmas2014: " + christmas2014); }
From source file:Main.java
public static String getTime() { return String.format("[%s:%s:%s]", zeroOne(LocalTime.now().getHour()), zeroOne(LocalTime.now().getMinute()), zeroOne(LocalTime.now().getSecond())); }