Its All Binary
.. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. .. ..
FRAME | NO FRAME | TREE

Package java.time

Class java.time.LocalDate

Examples for usage of all methods of 'java.time.LocalDate' with console output of example code.

Methods

Please click on method from below list to go to code example for usage of that method. Click [↓ Imports] to get import statements used in examples. To read javadoc of methods, click on [⿺ Javadoc] for that method.

Method Examples

public java.time.temporal.Temporal adjustInto(java.time.temporal.Temporal temporal)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDateTime localDateTime = LocalDateTime.of(2019, 01, 01, 1, 2, 3);
		System.out.println("localDateTime = " + localDateTime);
		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Adjustment will adjust date part of localDateTime to LocalDate but keep time
		// as it is.
		Temporal adjustedTemporal = localDate.adjustInto(localDateTime);
		System.out.println(
				"adjustedTemporal type = " + adjustedTemporal.getClass() + " adjusted value = " + adjustedTemporal);

		// Time part of localDateTime can't be adjusted in localDate as it does not
		// contain time. Hence exception.
		System.out.println(localDateTime.adjustInto(localDate));
	
					
Output:
localDateTime = 2019-01-01T01:02:03
localDate = 2019-06-14
adjustedTemporal type = class java.time.LocalDateTime adjusted value = 2019-06-14T01:02:03
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: NanoOfDay
	at java.base/java.time.LocalDate.with(LocalDate.java:1064)
	at java.base/java.time.LocalDate.with(LocalDate.java:139)
	at java.base/java.time.chrono.ChronoLocalDateTime.adjustInto(ChronoLocalDateTime.java:387)
	at java.base/java.time.LocalDateTime.adjustInto(LocalDateTime.java:1629)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_addIndexElement(LocalDateExamples.java:56)

Tag: Example for adjustInto method of class java.time.LocalDate., LocalDate adjustInto function example with arguments java.time.temporal.Temporal temporal, How to use adjustInto method of LocalDate?, Usage of LocalDate.adjustInto, LocalDate.adjustInto() examples

public java.time.LocalDateTime atStartOfDay()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime with midnight as time.
		LocalDateTime localDateTime = localDate.atStartOfDay();
		System.out.println("localDateTime = " + localDateTime);

	
					
Output:
localDate = 2019-06-14
localDateTime = 2019-06-14T00:00

Tag: Example for atStartOfDay method of class java.time.LocalDate., LocalDate atStartOfDay function example , How to use atStartOfDay method of LocalDate?, Usage of LocalDate.atStartOfDay, LocalDate.atStartOfDay() examples

public java.time.ZonedDateTime atStartOfDay(java.time.ZoneId zone)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to ZonedDateTime with midnight as time & pacific daylight
		// time zone.
		ZonedDateTime zonedDateTime = localDate.atStartOfDay(ZoneId.of("GMT-7"));
		System.out.println("zonedDateTime = " + zonedDateTime);

	
					
Output:
localDate = 2019-06-14
zonedDateTime = 2019-06-14T00:00-07:00[GMT-07:00]

Tag: Example for atStartOfDay method of class java.time.LocalDate., LocalDate atStartOfDay function example with arguments java.time.ZoneId zone, How to use atStartOfDay method of LocalDate?, Usage of LocalDate.atStartOfDay, LocalDate.atStartOfDay() examples

public java.time.LocalDateTime atTime(int hour, int minute)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime with 1 AM hour and 2 minute.
		LocalDateTime localDateTime = localDate.atTime(1, 2);
		System.out.println("localDateTime = " + localDateTime);

	
					
Output:
localDate = 2019-06-14
localDateTime = 2019-06-14T01:02

Tag: Example for atTime method of class java.time.LocalDate., LocalDate atTime function example with arguments int hour, int minute, How to use atTime method of LocalDate?, Usage of LocalDate.atTime, LocalDate.atTime() examples

public java.time.LocalDateTime atTime(int hour, int minute, int seconds)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime with 1 AM hour and 2 minute and 30
		// seconds.
		LocalDateTime localDateTime = localDate.atTime(1, 2, 30);
		System.out.println("localDateTime = " + localDateTime);

	
					
Output:
localDate = 2019-06-14
localDateTime = 2019-06-14T01:02:30

Tag: Example for atTime method of class java.time.LocalDate., LocalDate atTime function example with arguments int hour, int minute, int seconds, How to use atTime method of LocalDate?, Usage of LocalDate.atTime, LocalDate.atTime() examples

public java.time.LocalDateTime atTime(int hour, int minute, int seconds, int nanoOfSecond)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime with 1 AM hour and 2 minute and 30
		// seconds and 1200 nano seconds
		LocalDateTime localDateTime = localDate.atTime(1, 2, 30, 1200);
		System.out.println("localDateTime = " + localDateTime);

	
					
Output:
localDate = 2019-06-14
localDateTime = 2019-06-14T01:02:30.000001200

Tag: Example for atTime method of class java.time.LocalDate., LocalDate atTime function example with arguments int hour, int minute, int seconds, int nanoOfSecond, How to use atTime method of LocalDate?, Usage of LocalDate.atTime, LocalDate.atTime() examples

public java.time.LocalDateTime atTime(java.time.LocalTime localTime)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime using LocalTime with 1 AM hour and 2
		// minute and 30
		// seconds
		LocalTime localTime = LocalTime.of(1, 2, 30);
		LocalDateTime localDateTime = localDate.atTime(localTime);
		System.out.println("localDateTime = " + localDateTime);

		// Convert LocalDate to localdatetime using LocalTime with 1 AM hour and 2
		// minute and 30
		// seconds and 1200 nano seconds
		LocalTime localTime1 = LocalTime.of(1, 2, 30, 1200);
		LocalDateTime localDateTime1 = localDate.atTime(localTime1);
		System.out.println("localDateTime1 = " + localDateTime1);

	
					
Output:
localDate = 2019-06-14
localDateTime = 2019-06-14T01:02:30
localDateTime1 = 2019-06-14T01:02:30.000001200

Tag: Example for atTime method of class java.time.LocalDate., LocalDate atTime function example with arguments java.time.LocalTime localTime, How to use atTime method of LocalDate?, Usage of LocalDate.atTime, LocalDate.atTime() examples

public java.time.OffsetDateTime atTime(java.time.OffsetTime offsetTime)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 14);
		System.out.println("localDate = " + localDate);

		// Convert LocalDate to localdatetime using OffsetTime with 1 AM hour and 2
		// minute and 30 seconds and 1200 nano seconds and pacific daylight
		// time zone.
		OffsetTime offsetTime = OffsetTime.of(1, 2, 30, 1200, ZoneOffset.of("-7"));
		OffsetDateTime offsetDateTime = localDate.atTime(offsetTime);
		System.out.println("offsetDateTime = " + offsetDateTime);

	
					
Output:
localDate = 2019-06-14
offsetDateTime = 2019-06-14T01:02:30.000001200-07:00

Tag: Example for atTime method of class java.time.LocalDate., LocalDate atTime function example with arguments java.time.OffsetTime offsetTime, How to use atTime method of LocalDate?, Usage of LocalDate.atTime, LocalDate.atTime() examples

public int compareTo(java.time.chrono.ChronoLocalDate other)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDateJune = LocalDate.of(2019, 06, 14);
		LocalDate localDateJuneSame = LocalDate.of(2019, 06, 14);
		LocalDate localDateJan = LocalDate.of(2019, 01, 14);
		LocalDate localDateDec = LocalDate.of(2019, 12, 14);

		// negative means localDateJune is less, positive means localDateJune is
		// greater, zero means both equals
		System.out.println("Comparison of " + localDateJune + " & " + localDateJuneSame + " = "
				+ localDateJune.compareTo(localDateJuneSame));

		System.out.println("Comparison of " + localDateJune + " & " + localDateJan + " = "
				+ localDateJune.compareTo(localDateJan));

		System.out.println("Comparison of " + localDateJune + " & " + localDateDec + " = "
				+ localDateJune.compareTo(localDateDec));

		// Comparison of dates of different chronology
		LocalDate now = LocalDate.now();
		ThaiBuddhistDate thaiNow = ThaiBuddhistDate.now();
		// WRONG WAY to do compareTo of different chronology dates.
		System.out.println("(WRONG WAY!) Comparison of " + now + " & " + thaiNow + " = " + now.compareTo(thaiNow));
		// RIGHT WAY to do compareTo of different chronology dates.
		System.out.println("(RIGHT WAY!) Comparison of LocalDate-" + now.toEpochDay() + " & ThaiBuddhistDate-"
				+ thaiNow.toEpochDay() + " = " + Long.compare(now.toEpochDay(), thaiNow.toEpochDay()));

	
					
Output:
Comparison of 2019-06-14 & 2019-06-14 = 0
Comparison of 2019-06-14 & 2019-01-14 = 5
Comparison of 2019-06-14 & 2019-12-14 = -6
(WRONG WAY!) Comparison of 2019-11-02 & ThaiBuddhist BE 2562-11-02 = -11
(RIGHT WAY!) Comparison of LocalDate-18202 & ThaiBuddhistDate-18202 = 0

Tag: Example for compareTo method of class java.time.LocalDate., LocalDate compareTo function example with arguments java.time.chrono.ChronoLocalDate other, How to use compareTo method of LocalDate?, Usage of LocalDate.compareTo, LocalDate.compareTo() examples

public java.util.stream.Stream<java.time.LocalDate> datesUntil(java.time.LocalDate endExclusive)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate christmas = LocalDate.of(2019, 12, 25);
		LocalDate newYear = LocalDate.of(2020, 01, 01);

		System.out.println("Holiday dates are");
		// End is exclusive, so new years day is not considered. If needed, use next day
		// as method argument.
		christmas.datesUntil(newYear).forEach(System.out::println);

	
					
Output:
Holiday dates are
2019-12-25
2019-12-26
2019-12-27
2019-12-28
2019-12-29
2019-12-30
2019-12-31

Tag: Example for datesUntil method of class java.time.LocalDate., LocalDate datesUntil function example with arguments java.time.LocalDate endExclusive, How to use datesUntil method of LocalDate?, Usage of LocalDate.datesUntil, LocalDate.datesUntil() examples

public java.util.stream.Stream<java.time.LocalDate> datesUntil(java.time.LocalDate endExclusive, java.time.Period step)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate newYear2019 = LocalDate.of(2019, 01, 01);
		LocalDate yearEnd2019 = LocalDate.of(2019, 12, 31);

		System.out.println("Monthly salary pay dates are");
		// Give dates from newYear2019 till yearEnd2019 with 1 month gap.
		newYear2019.datesUntil(yearEnd2019, Period.ofMonths(1)).forEach(System.out::println);

	
					
Output:
Monthly salary pay dates are
2019-01-01
2019-02-01
2019-03-01
2019-04-01
2019-05-01
2019-06-01
2019-07-01
2019-08-01
2019-09-01
2019-10-01
2019-11-01
2019-12-01

Tag: Example for datesUntil method of class java.time.LocalDate., LocalDate datesUntil function example with arguments java.time.LocalDate endExclusive, java.time.Period step, How to use datesUntil method of LocalDate?, Usage of LocalDate.datesUntil, LocalDate.datesUntil() examples

public boolean equals(java.lang.Object other)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate newYear2019 = LocalDate.of(2019, 01, 01);
		LocalDate sameDate = LocalDate.of(2019, 01, 01);
		LocalDate differentDate = LocalDate.of(2019, 06, 15);

		// Equality of dates of same chronology.
		System.out.println(
				"Are these equals()? " + newYear2019 + " & " + sameDate + " = " + newYear2019.equals(sameDate));
		System.out.println("Are these equals()? " + newYear2019 + " & " + differentDate + " = "
				+ newYear2019.equals(differentDate));

		// Equality of dates of different chronology
		LocalDate now = LocalDate.now();
		ThaiBuddhistDate thaiNow = ThaiBuddhistDate.now();
		// WRONG WAY to do equals for dates of different chronology.
		System.out.println("Are these equals()? (WRONG WAY!) " + now + " & " + thaiNow + " = " + now.equals(thaiNow));
		// RIGHT WAY to do equals for dates of different chronology using epoch day.
		System.out.println("Are these equals()? (RIGHT WAY!) LocalDate-" + now.toEpochDay() + " & ThaiBuddhistDate-"
				+ thaiNow.toEpochDay() + " = " + Long.valueOf(now.toEpochDay()).equals(thaiNow.toEpochDay()));

	
					
Output:
Are these equals()? 2019-01-01 & 2019-01-01 = true
Are these equals()? 2019-01-01 & 2019-06-15 = false
Are these equals()? (WRONG WAY!) 2019-11-02 & ThaiBuddhist BE 2562-11-02 = false
Are these equals()? (RIGHT WAY!) LocalDate-18202 & ThaiBuddhistDate-18202 = true

Tag: Example for equals method of class java.time.LocalDate., LocalDate equals function example with arguments java.lang.Object other, How to use equals method of LocalDate?, Usage of LocalDate.equals, LocalDate.equals() examples

public java.lang.String format(java.time.format.DateTimeFormatter formatter)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate newYear2019 = LocalDate.of(2019, 01, 01);

		String formattedDate_RFC_1123_DATE_TIME = newYear2019
				.format(DateTimeFormatter.ofLocalizedDate(java.time.format.FormatStyle.FULL));
		System.out.println("Formatted date FormatStyle.FULL= " + formattedDate_RFC_1123_DATE_TIME);

		String formattedDate_ISO_LOCAL_DATE = newYear2019.format(DateTimeFormatter.ISO_LOCAL_DATE);
		System.out.println("Formatted date ISO_LOCAL_DATE = " + formattedDate_ISO_LOCAL_DATE);

		// Wrong format. LocalDate does not have time but lets try to format using
		// format with time. Causes UnsupportedTemporalTypeException
		String formattedDate_ISO_LOCAL_DATE_TIME = newYear2019.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
		System.out.println("Formatted date ISO_LOCAL_DATE_TIME = " + formattedDate_ISO_LOCAL_DATE_TIME);

	
					
Output:
Formatted date FormatStyle.FULL= Tuesday, January 1, 2019
Formatted date ISO_LOCAL_DATE = 2019-01-01
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: HourOfDay
	at java.base/java.time.LocalDate.get0(LocalDate.java:708)
	at java.base/java.time.LocalDate.getLong(LocalDate.java:687)
	at java.base/java.time.format.DateTimePrintContext.getValue(DateTimePrintContext.java:308)
	at java.base/java.time.format.DateTimeFormatterBuilder$NumberPrinterParser.format(DateTimeFormatterBuilder.java:2696)
	at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2335)
	at java.base/java.time.format.DateTimeFormatterBuilder$CompositePrinterParser.format(DateTimeFormatterBuilder.java:2335)
	at java.base/java.time.format.DateTimeFormatter.formatTo(DateTimeFormatter.java:1843)
	at java.base/java.time.format.DateTimeFormatter.format(DateTimeFormatter.java:1817)
	at java.base/java.time.LocalDate.format(LocalDate.java:1816)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_format(LocalDateExamples.java:261)

Tag: Example for format method of class java.time.LocalDate., LocalDate format function example with arguments java.time.format.DateTimeFormatter formatter, How to use format method of LocalDate?, Usage of LocalDate.format, LocalDate.format() examples

public static java.time.LocalDate from(java.time.temporal.TemporalAccessor temporal)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		// Convert LocalDateTime to LocalDate
		LocalDateTime localDateTime = LocalDateTime.of(2019, 01, 01, 1, 2, 3);
		LocalDate localDate = LocalDate.from(localDateTime);
		System.out.println("Converted LocalDateTime " + localDateTime + " to LocalDate " + localDate);

		// Convert ZonedDateTime to LocalDate
		ZonedDateTime zonedDateTime = ZonedDateTime.of(2019, 1, 1, 1, 1, 1, 0, ZoneId.of("GMT-7"));
		LocalDate localDateFromzonedDateTime = LocalDate.from(zonedDateTime);
		System.out.println("Converted ZonedDateTime " + zonedDateTime + " to LocalDate " + localDateFromzonedDateTime);

		// Convert other ChronoLocalDate like ThaiBuddhistDate to LocalDate. Conversion
		// from different chronology to LocalDate
		ThaiBuddhistDate thaiNow = ThaiBuddhistDate.now();
		LocalDate localDateNow = LocalDate.from(thaiNow);
		System.out.println("Converted ThaiBuddhistDate " + thaiNow + " to LocalDate " + localDateNow);

	
					
Output:
Converted LocalDateTime 2019-01-01T01:02:03 to LocalDate 2019-01-01
Converted ZonedDateTime 2019-01-01T01:01:01-07:00[GMT-07:00] to LocalDate 2019-01-01
Converted ThaiBuddhistDate ThaiBuddhist BE 2562-11-02 to LocalDate 2019-11-02

Tag: Example for from method of class java.time.LocalDate., LocalDate from function example with arguments java.time.temporal.TemporalAccessor temporal, How to use from method of LocalDate?, Usage of LocalDate.from, LocalDate.from() examples

public int get(java.time.temporal.TemporalField field)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		// Get temporal fields from LocalDate.
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		// Get year from LocalDate
		int year = localDate.get(ChronoField.YEAR);
		System.out.println("YEAR = " + year);
		// Get month from LocalDate
		System.out.println("MONTH_OF_YEAR = " + localDate.get(ChronoField.MONTH_OF_YEAR));
		// Get day or date from LocalDate
		System.out.println("DAY_OF_MONTH = " + localDate.get(ChronoField.DAY_OF_MONTH));

		// LocalDate does not have time. Lets try fetching time field. Will cause
		// exception. Use isSupported to avoid exception.
		System.out.println("CLOCK_HOUR_OF_DAY = " + localDate.get(ChronoField.CLOCK_HOUR_OF_DAY));

	
					
Output:
YEAR = 2019
MONTH_OF_YEAR = 6
DAY_OF_MONTH = 15
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: ClockHourOfDay
	at java.base/java.time.LocalDate.get0(LocalDate.java:708)
	at java.base/java.time.LocalDate.get(LocalDate.java:650)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_get(LocalDateExamples.java:303)

Tag: Example for get method of class java.time.LocalDate., LocalDate get function example with arguments java.time.temporal.TemporalField field, How to use get method of LocalDate?, Usage of LocalDate.get, LocalDate.get() examples

public java.time.chrono.IsoChronology getChronology()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		IsoChronology chronology = localDate.getChronology();
		System.out.println("chronology = " + chronology);
		System.out.println("CalendarType = " + chronology.getCalendarType());
		System.out.println("chronology id	 = " + chronology.getId());

	
					
Output:
chronology = ISO
CalendarType = iso8601
chronology id	 = ISO

Tag: Example for getChronology method of class java.time.LocalDate., LocalDate getChronology function example , How to use getChronology method of LocalDate?, Usage of LocalDate.getChronology, LocalDate.getChronology() examples

public int getDayOfMonth()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate1 = LocalDate.of(2019, 06, 15);
		System.out.println("getDayOfMonth = " + localDate1.getDayOfMonth());

		LocalDate localDate2 = LocalDate.of(2019, 12, 31);
		System.out.println("getDayOfMonth = " + localDate2.getDayOfMonth());

		LocalDate localDate3 = LocalDate.of(2019, 01, 1);
		System.out.println("getDayOfMonth = " + localDate3.getDayOfMonth());

	
					
Output:
getDayOfMonth = 15
getDayOfMonth = 31
getDayOfMonth = 1

Tag: Example for getDayOfMonth method of class java.time.LocalDate., LocalDate getDayOfMonth function example , How to use getDayOfMonth method of LocalDate?, Usage of LocalDate.getDayOfMonth, LocalDate.getDayOfMonth() examples

public java.time.DayOfWeek getDayOfWeek()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate1 = LocalDate.of(2019, 06, 15);
		DayOfWeek dayOfWeek1 = localDate1.getDayOfWeek();
		System.out.println("getDayOfWeek = " + dayOfWeek1.name());

		LocalDate localDate2 = LocalDate.of(2019, 12, 31);
		DayOfWeek dayOfWeek2 = localDate2.getDayOfWeek();
		System.out.println("getDayOfWeek = " + dayOfWeek2.name());

		LocalDate localDate3 = LocalDate.of(2019, 01, 1);
		DayOfWeek dayOfWeek3 = localDate3.getDayOfWeek();
		System.out.println("getDayOfWeek = " + dayOfWeek3.name());

	
					
Output:
getDayOfWeek = SATURDAY
getDayOfWeek = TUESDAY
getDayOfWeek = TUESDAY

Tag: Example for getDayOfWeek method of class java.time.LocalDate., LocalDate getDayOfWeek function example , How to use getDayOfWeek method of LocalDate?, Usage of LocalDate.getDayOfWeek, LocalDate.getDayOfWeek() examples

public int getDayOfYear()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate1 = LocalDate.of(2019, 06, 15);
		int dayOfYear1 = localDate1.getDayOfYear();
		System.out.println("dayOfYear = " + dayOfYear1);

		LocalDate localDate2 = LocalDate.of(2019, 12, 31);
		int dayOfYear2 = localDate2.getDayOfYear();
		System.out.println("dayOfYear = " + dayOfYear2);

		LocalDate localDate3 = LocalDate.of(2019, 01, 1);
		int dayOfYear3 = localDate3.getDayOfYear();
		System.out.println("dayOfYear = " + dayOfYear3);

	
					
Output:
dayOfYear = 166
dayOfYear = 365
dayOfYear = 1

Tag: Example for getDayOfYear method of class java.time.LocalDate., LocalDate getDayOfYear function example , How to use getDayOfYear method of LocalDate?, Usage of LocalDate.getDayOfYear, LocalDate.getDayOfYear() examples

public java.time.chrono.IsoEra getEra()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		IsoEra isoEra = localDate.getEra();
		System.out.println("Era = " + isoEra.name());
	
					
Output:
Era = CE

Tag: Example for getEra method of class java.time.LocalDate., LocalDate getEra function example , How to use getEra method of LocalDate?, Usage of LocalDate.getEra, LocalDate.getEra() examples

public long getLong(java.time.temporal.TemporalField field)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		// Get temporal fields from LocalDate.
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		// Get year from LocalDate
		long year = localDate.getLong(ChronoField.YEAR);
		System.out.println("YEAR = " + year);
		// Get month from LocalDate
		System.out.println("MONTH_OF_YEAR = " + localDate.getLong(ChronoField.MONTH_OF_YEAR));
		// Get day or date from LocalDate
		System.out.println("DAY_OF_MONTH = " + localDate.getLong(ChronoField.DAY_OF_MONTH));

		// LocalDate does not have time. Lets try fetching time field. Will cause
		// exception.
		System.out.println("CLOCK_HOUR_OF_DAY = " + localDate.getLong(ChronoField.CLOCK_HOUR_OF_DAY));
	
					
Output:
YEAR = 2019
MONTH_OF_YEAR = 6
DAY_OF_MONTH = 15
java.time.temporal.UnsupportedTemporalTypeException: Unsupported field: ClockHourOfDay
	at java.base/java.time.LocalDate.get0(LocalDate.java:708)
	at java.base/java.time.LocalDate.getLong(LocalDate.java:687)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_getLong(LocalDateExamples.java:389)

Tag: Example for getLong method of class java.time.LocalDate., LocalDate getLong function example with arguments java.time.temporal.TemporalField field, How to use getLong method of LocalDate?, Usage of LocalDate.getLong, LocalDate.getLong() examples

public java.time.Month getMonth()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		Month month = localDate.getMonth();
		System.out.println("Month = " + month.name());
		System.out.println("Max days in Month = " + month.maxLength());
	
					
Output:
Month = JUNE
Max days in Month = 30

Tag: Example for getMonth method of class java.time.LocalDate., LocalDate getMonth function example , How to use getMonth method of LocalDate?, Usage of LocalDate.getMonth, LocalDate.getMonth() examples

public int getMonthValue()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 15);
		int month = localDate.getMonthValue();
		System.out
				.println("Month int = '" + month + "' convert int month to Month instance = '" + Month.of(month) + "'");
		System.out.println("Max days in Month = " + Month.of(month).maxLength());

	
					
Output:
Month int = '6' convert int month to Month instance = 'JUNE'
Max days in Month = 30

Tag: Example for getMonthValue method of class java.time.LocalDate., LocalDate getMonthValue function example , How to use getMonthValue method of LocalDate?, Usage of LocalDate.getMonthValue, LocalDate.getMonthValue() examples

public int getYear()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		int year = localDate.getYear();
		System.out.println("Year = " + year);
	
					
Output:
Year = 2019

Tag: Example for getYear method of class java.time.LocalDate., LocalDate getYear function example , How to use getYear method of LocalDate?, Usage of LocalDate.getYear, LocalDate.getYear() examples

public boolean isAfter(java.time.chrono.ChronoLocalDate other)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		LocalDate endOfYear = LocalDate.of(2019, 12, 31);
		LocalDate startOfYear = LocalDate.of(2019, 01, 1);

		ThaiBuddhistDate thaiLocalDate = ThaiBuddhistDate.from(localDate);

		System.out.println("Is " + localDate + " after " + endOfYear + "? " + localDate.isAfter(endOfYear));
		System.out.println("Is " + localDate + " after " + startOfYear + "? " + localDate.isAfter(startOfYear));

		// Compare with different chronology date doesn't work. isAfter doesn't consider
		// chronology, so don't use across different chronological date.
		System.out.println("Is thai date " + thaiLocalDate + " after " + endOfYear + "? (WRONG RESULT) "
				+ localDate.isAfter(thaiLocalDate));
		System.out.println("Is thai date " + thaiLocalDate + " after " + startOfYear + "? (WRONG RESULT) "
				+ localDate.isAfter(thaiLocalDate));
	
					
Output:
Is 2019-06-15 after 2019-12-31? false
Is 2019-06-15 after 2019-01-01? true
Is thai date ThaiBuddhist BE 2562-06-15 after 2019-12-31? (WRONG RESULT) false
Is thai date ThaiBuddhist BE 2562-06-15 after 2019-01-01? (WRONG RESULT) false

Tag: Example for isAfter method of class java.time.LocalDate., LocalDate isAfter function example with arguments java.time.chrono.ChronoLocalDate other, How to use isAfter method of LocalDate?, Usage of LocalDate.isAfter, LocalDate.isAfter() examples

public boolean isBefore(java.time.chrono.ChronoLocalDate other)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		LocalDate endOfYear = LocalDate.of(2019, 12, 31);
		LocalDate startOfYear = LocalDate.of(2019, 01, 1);

		ThaiBuddhistDate thaiLocalDate = ThaiBuddhistDate.from(localDate);

		System.out.println("Is " + localDate + " before " + endOfYear + "? " + localDate.isBefore(endOfYear));
		System.out.println("Is " + localDate + " before " + startOfYear + "? " + localDate.isBefore(startOfYear));

		// Compare with different chronology date doesn't work. isBefore doesn't
		// consider chronology, so don't use across different chronological date.
		System.out.println("Is thai date " + thaiLocalDate + " before " + endOfYear + "? (WRONG RESULT) "
				+ localDate.isBefore(thaiLocalDate));
		System.out.println("Is thai date " + thaiLocalDate + " before " + startOfYear + "? (WRONG RESULT) "
				+ localDate.isBefore(thaiLocalDate));
	
					
Output:
Is 2019-06-15 before 2019-12-31? true
Is 2019-06-15 before 2019-01-01? false
Is thai date ThaiBuddhist BE 2562-06-15 before 2019-12-31? (WRONG RESULT) false
Is thai date ThaiBuddhist BE 2562-06-15 before 2019-01-01? (WRONG RESULT) false

Tag: Example for isBefore method of class java.time.LocalDate., LocalDate isBefore function example with arguments java.time.chrono.ChronoLocalDate other, How to use isBefore method of LocalDate?, Usage of LocalDate.isBefore, LocalDate.isBefore() examples

public boolean isEqual(java.time.chrono.ChronoLocalDate other)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		LocalDate otherSameDate = LocalDate.of(2019, 06, 15);
		LocalDate endOfYear = LocalDate.of(2019, 12, 31);

		ThaiBuddhistDate thaiLocalDate = ThaiBuddhistDate.from(localDate);

		System.out.println("Is " + localDate + " equals " + endOfYear + "? " + localDate.isEqual(endOfYear));
		System.out.println("Is " + localDate + " equals " + otherSameDate + "? " + localDate.isEqual(otherSameDate));

		// isEqual with different chronology date doesn't work. isEqual doesn't
		// consider chronology, so don't use across different chronological date.
		System.out.println("Is thai date " + thaiLocalDate + " equals " + localDate + "? (WRONG RESULT) "
				+ localDate.isEqual(thaiLocalDate));
	
					
Output:
Is 2019-06-15 equals 2019-12-31? false
Is 2019-06-15 equals 2019-06-15? true
Is thai date ThaiBuddhist BE 2562-06-15 equals 2019-06-15? (WRONG RESULT) true

Tag: Example for isEqual method of class java.time.LocalDate., LocalDate isEqual function example with arguments java.time.chrono.ChronoLocalDate other, How to use isEqual method of LocalDate?, Usage of LocalDate.isEqual, LocalDate.isEqual() examples

public boolean isLeapYear()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate2019 = LocalDate.of(2019, 06, 15);
		LocalDate localDate2020 = LocalDate.of(2020, 06, 15);

		System.out.println("Is Leap 2019 Year " + localDate2019.isLeapYear());
		System.out.println("Is Leap 2020 Year " + localDate2020.isLeapYear());
	
					
Output:
Is Leap 2019 Year false
Is Leap 2020 Year true

Tag: Example for isLeapYear method of class java.time.LocalDate., LocalDate isLeapYear function example , How to use isLeapYear method of LocalDate?, Usage of LocalDate.isLeapYear, LocalDate.isLeapYear() examples

public boolean isSupported(java.time.temporal.TemporalUnit unit)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		System.out.println("Is DAYS supported? " + localDate.isSupported(ChronoUnit.DAYS));
		System.out.println("Is MONTHS supported? " + localDate.isSupported(ChronoUnit.MONTHS));
		System.out.println("Is YEARS supported? " + localDate.isSupported(ChronoUnit.YEARS));
		System.out.println("Is HOURS supported? " + localDate.isSupported(ChronoUnit.HOURS));
		System.out.println("Is MINUTES supported? " + localDate.isSupported(ChronoUnit.MINUTES));
		System.out.println("Is SECONDS supported? " + localDate.isSupported(ChronoUnit.SECONDS));

	
					
Output:
Is DAYS supported? true
Is MONTHS supported? true
Is YEARS supported? true
Is HOURS supported? false
Is MINUTES supported? false
Is SECONDS supported? false

Tag: Example for isSupported method of class java.time.LocalDate., LocalDate isSupported function example with arguments java.time.temporal.TemporalUnit unit, How to use isSupported method of LocalDate?, Usage of LocalDate.isSupported, LocalDate.isSupported() examples

public boolean isSupported(java.time.temporal.TemporalField field)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		System.out.println("Is DAY_OF_MONTH supported? " + localDate.isSupported(ChronoField.DAY_OF_MONTH));
		System.out.println("Is DAY_OF_YEAR supported? " + localDate.isSupported(ChronoField.DAY_OF_YEAR));
		System.out.println("Is MONTH_OF_YEAR supported? " + localDate.isSupported(ChronoField.MONTH_OF_YEAR));
		System.out.println("Is YEAR supported? " + localDate.isSupported(ChronoField.YEAR));
		System.out.println("Is HOUR_OF_DAY supported? " + localDate.isSupported(ChronoField.HOUR_OF_DAY));
		System.out.println("Is MINUTE_OF_HOUR supported? " + localDate.isSupported(ChronoField.MINUTE_OF_HOUR));
		System.out.println("Is SECOND_OF_MINUTE supported? " + localDate.isSupported(ChronoField.SECOND_OF_MINUTE));
	
					
Output:
Is DAY_OF_MONTH supported? true
Is DAY_OF_YEAR supported? true
Is MONTH_OF_YEAR supported? true
Is YEAR supported? true
Is HOUR_OF_DAY supported? false
Is MINUTE_OF_HOUR supported? false
Is SECOND_OF_MINUTE supported? false

Tag: Example for isSupported method of class java.time.LocalDate., LocalDate isSupported function example with arguments java.time.temporal.TemporalField field, How to use isSupported method of LocalDate?, Usage of LocalDate.isSupported, LocalDate.isSupported() examples

public int lengthOfMonth()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		int lengthOfMonth = localDate.lengthOfMonth();
		System.out.println("Length of month i.e. number of days in month = " + lengthOfMonth);

		LocalDate localDateFeb = LocalDate.of(2019, 02, 15);
		int lengthOfMonthFeb = localDateFeb.lengthOfMonth();
		System.out.println("Length of month Feb 2019 i.e. number of days in month = " + lengthOfMonthFeb);

		LocalDate localDateFeb2020 = LocalDate.of(2020, 02, 15);
		int lengthOfMonthFeb2020 = localDateFeb2020.lengthOfMonth();
		System.out.println("Length of month Feb 2020 i.e. number of days in month = " + lengthOfMonthFeb2020);
	
					
Output:
Length of month i.e. number of days in month = 30
Length of month Feb 2019 i.e. number of days in month = 28
Length of month Feb 2020 i.e. number of days in month = 29

Tag: Example for lengthOfMonth method of class java.time.LocalDate., LocalDate lengthOfMonth function example , How to use lengthOfMonth method of LocalDate?, Usage of LocalDate.lengthOfMonth, LocalDate.lengthOfMonth() examples

public int lengthOfYear()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);
		int lengthOfYear = localDate.lengthOfYear();
		System.out.println("Length of year 2019 i.e. number of days in year = " + lengthOfYear);

		LocalDate localDateFeb2020 = LocalDate.of(2020, 02, 15);
		int lengthOfYear2020 = localDateFeb2020.lengthOfYear();
		System.out.println("Length of year 2020 i.e. number of days in year = " + lengthOfYear2020);
	
					
Output:
Length of year 2019 i.e. number of days in year = 365
Length of year 2020 i.e. number of days in year = 366

Tag: Example for lengthOfYear method of class java.time.LocalDate., LocalDate lengthOfYear function example , How to use lengthOfYear method of LocalDate?, Usage of LocalDate.lengthOfYear, LocalDate.lengthOfYear() examples

public java.time.LocalDate minus(java.time.temporal.TemporalAmount amountToSubtract)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 06, 15);

		// Period implements TemporalAmount. Lets use concrete Period for minus
		TemporalAmount temporalAmount4Days = Period.ofDays(4);
		LocalDate localDateMinus4Days = localDate.minus(temporalAmount4Days);
		System.out.println("localDateMinus4Days = " + localDateMinus4Days);

		TemporalAmount temporalAmount2Months = Period.ofMonths(2);
		LocalDate localDateMinus2Months = localDate.minus(temporalAmount2Months);
		System.out.println("localDateMinus2Months = " + localDateMinus2Months);

		TemporalAmount tempAm1Year2Days4Months = Period.of(1, 2, 4);
		LocalDate localDateMinus1Year2Days4Months = localDate.minus(tempAm1Year2Days4Months);
		System.out.println("localDateMinus1Year2Days4Months = " + localDateMinus1Year2Days4Months);

		TemporalAmount temporalAmountDuration = Duration.ofDays(3);
		// Duration also implements TemporalAmount, but Duration is time based.
		// LocalDate does not contain time. so this will fail with exception.
		LocalDate localDateMinus4DaysDuration = localDate.minus(temporalAmountDuration);
		System.out.println("localDateMinus4Days = " + localDateMinus4DaysDuration);
	
					
Output:
localDateMinus4Days = 2019-06-11
localDateMinus2Months = 2019-04-15
localDateMinus1Year2Days4Months = 2018-04-11
java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Seconds
	at java.base/java.time.LocalDate.plus(LocalDate.java:1272)
	at java.base/java.time.LocalDate.minus(LocalDate.java:1448)
	at java.base/java.time.LocalDate.minus(LocalDate.java:139)
	at java.base/java.time.Duration.subtractFrom(Duration.java:1137)
	at java.base/java.time.LocalDate.minus(LocalDate.java:1424)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_minus_TemporalAmount(LocalDateExamples.java:561)

Tag: Example for minus method of class java.time.LocalDate., LocalDate minus function example with arguments java.time.temporal.TemporalAmount amountToSubtract, How to use minus method of LocalDate?, Usage of LocalDate.minus, LocalDate.minus() examples

public java.time.LocalDate minus(long amountToSubtract, java.time.temporal.TemporalUnit unit)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 15);

		LocalDate localDateMinus4Days = localDate.minus(4, ChronoUnit.DAYS);
		System.out.println("localDateMinus4Days = " + localDateMinus4Days);

		LocalDate localDateMinus2Months = localDate.minus(2, ChronoUnit.MONTHS);
		System.out.println("localDateMinus2Months = " + localDateMinus2Months);

		// LocalDate does not contain time. so this will fail with exception.
		LocalDate localDateMinus24Hours = localDate.minus(24, ChronoUnit.HOURS);
		System.out.println("localDateMinus24Hours = " + localDateMinus24Hours);

	
					
Output:
localDateMinus4Days = 2019-06-11
localDateMinus2Months = 2019-04-15
java.time.temporal.UnsupportedTemporalTypeException: Unsupported unit: Hours
	at java.base/java.time.LocalDate.plus(LocalDate.java:1272)
	at java.base/java.time.LocalDate.minus(LocalDate.java:1448)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_minus_long_TemporalUnit(LocalDateExamples.java:578)

Tag: Example for minus method of class java.time.LocalDate., LocalDate minus function example with arguments long amountToSubtract, java.time.temporal.TemporalUnit unit, How to use minus method of LocalDate?, Usage of LocalDate.minus, LocalDate.minus() examples

public java.time.LocalDate minusDays(long daysToSubtract)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 15);

		// Day changed in same month as per subtraction result
		LocalDate localDateMinus4Days = localDate.minusDays(4);
		System.out.println("localDateMinus4Days = " + localDateMinus4Days);

		// Day & month changed as per subtraction result
		LocalDate localDateMinus40Days = localDate.minusDays(40);
		System.out.println("localDateMinus40Days = " + localDateMinus40Days);

		// Day, month & year changed as per subtraction result
		LocalDate localDateMinus400Days = localDate.minusDays(400);
		System.out.println("localDateMinus400Days = " + localDateMinus400Days);

	
					
Output:
localDateMinus4Days = 2019-06-11
localDateMinus40Days = 2019-05-06
localDateMinus400Days = 2018-05-11

Tag: Example for minusDays method of class java.time.LocalDate., LocalDate minusDays function example with arguments long daysToSubtract, How to use minusDays method of LocalDate?, Usage of LocalDate.minusDays, LocalDate.minusDays() examples

public java.time.LocalDate minusMonths(long monthsToSubtract)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 30);

		LocalDate localDateMinus2Months = localDate.minusMonths(2);
		System.out.println("localDateMinus2Months = " + localDateMinus2Months);

		LocalDate localDateMinus20Months = localDate.minusMonths(20);
		System.out.println("localDateMinus20Months = " + localDateMinus20Months);

		LocalDate localDateToFeb = localDate.minusMonths(4);
		// Since we are doing minus 4 months which is Feb & Feb does not have day 30,
		// hence it is adjusted to 28 i.e. last day on Feb month.
		System.out.println("localDateToFeb (Notice day of month changed from 30 to 28) = " + localDateToFeb);

	
					
Output:
localDateMinus2Months = 2019-04-30
localDateMinus20Months = 2017-10-30
localDateToFeb (Notice day of month changed from 30 to 28) = 2019-02-28

Tag: Example for minusMonths method of class java.time.LocalDate., LocalDate minusMonths function example with arguments long monthsToSubtract, How to use minusMonths method of LocalDate?, Usage of LocalDate.minusMonths, LocalDate.minusMonths() examples

public java.time.LocalDate minusWeeks(long weeksToSubtract)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 15);

		// Day changed in same month as per subtraction result
		LocalDate localDateMinus1Week = localDate.minusWeeks(1);
		System.out.println("localDateMinus1Week = " + localDateMinus1Week);

		// Day & month changed as per subtraction result
		LocalDate localDateMinus5Week = localDate.minusWeeks(5);
		System.out.println("localDateMinus5Week = " + localDateMinus5Week);

		// Day, month & year changed as per subtraction result
		LocalDate localDateMinus50Week = localDate.minusWeeks(50);
		System.out.println("localDateMinus50Week = " + localDateMinus50Week);

	
					
Output:
localDateMinus1Week = 2019-06-08
localDateMinus5Week = 2019-05-11
localDateMinus50Week = 2018-06-30

Tag: Example for minusWeeks method of class java.time.LocalDate., LocalDate minusWeeks function example with arguments long weeksToSubtract, How to use minusWeeks method of LocalDate?, Usage of LocalDate.minusWeeks, LocalDate.minusWeeks() examples

public java.time.LocalDate minusYears(long yearsToSubtract)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate localDate = LocalDate.of(2019, 06, 30);

		LocalDate localDateMinus1year = localDate.minusYears(1);
		System.out.println("localDateMinus1year = " + localDateMinus1year);

		LocalDate localDateMinus5year = localDate.minusYears(5);
		System.out.println("localDateMinus5year = " + localDateMinus5year);

		LocalDate localDateMinus100year = localDate.minusYears(100);
		System.out.println("localDateMinus100year = " + localDateMinus100year);

		// Subtract lot of years just to try. This will cause DateTimeException becasue
		// this is out of date range.
		LocalDate localDateMinusLotOfyear = localDate.minusYears(Long.MAX_VALUE);
		System.out.println("localDateMinusLotOfyear = " + localDateMinusLotOfyear);

	
					
Output:
localDateMinus1year = 2018-06-30
localDateMinus5year = 2014-06-30
localDateMinus100year = 1919-06-30
java.time.DateTimeException: Invalid value for Year (valid values -999999999 - 999999999): -9223372036854773788
	at java.base/java.time.temporal.ValueRange.checkValidIntValue(ValueRange.java:330)
	at java.base/java.time.temporal.ChronoField.checkValidIntValue(ChronoField.java:736)
	at java.base/java.time.LocalDate.plusYears(LocalDate.java:1302)
	at java.base/java.time.LocalDate.minusYears(LocalDate.java:1473)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_minusYears(LocalDateExamples.java:659)

Tag: Example for minusYears method of class java.time.LocalDate., LocalDate minusYears function example with arguments long yearsToSubtract, How to use minusYears method of LocalDate?, Usage of LocalDate.minusYears, LocalDate.minusYears() examples

public static java.time.LocalDate now()

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		LocalDate now = LocalDate.now();
		System.out.println("Today's date is " + now);

		// Date is taken from default time zone.
		TimeZone old = TimeZone.getDefault();
		System.out.println("Current default timezone = " + old.getDisplayName());

		// Lets try changing default to India timezone.
		TimeZone.setDefault(TimeZone.getTimeZone("GMT+5:30"));
		// LocalDate now in different timezone i.e. India
		LocalDate nowInIndia = LocalDate.now();
		System.out.println("Today's date in modified timezone of India is " + nowInIndia);

		// Set old timezone back
		TimeZone.setDefault(old);
	
					
Output:
Today's date is 2019-11-02
Current default timezone = Pacific Standard Time
Today's date in modified timezone of India is 2019-11-03

Tag: Example for now method of class java.time.LocalDate., LocalDate now function example , How to use now method of LocalDate?, Usage of LocalDate.now, LocalDate.now() examples

public static java.time.LocalDate now(java.time.Clock clock)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		// LocalDate in default timezone clock
		LocalDate nowDefault = LocalDate.now(Clock.systemDefaultZone());
		System.out.println("Today's date is " + nowDefault);

		// LocalDate in UTC clock
		LocalDate nowUTC = LocalDate.now(Clock.systemUTC());
		System.out.println("Today's UTC date is " + nowUTC);

		// Now LocalDate in different timezone using ZoneId
		LocalDate nowIndia = LocalDate.now(Clock.system(ZoneId.of("UTC+05:30")));
		System.out.println("Today's date in India is " + nowIndia);
	
					
Output:
Today's date is 2019-11-02
Today's UTC date is 2019-11-03
Today's date in India is 2019-11-03

Tag: Example for now method of class java.time.LocalDate., LocalDate now function example with arguments java.time.Clock clock, How to use now method of LocalDate?, Usage of LocalDate.now, LocalDate.now() examples, Create todays now LocalDate from any timezone., Create LocalDate using clock instance

public static java.time.LocalDate now(java.time.ZoneId zoneId)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		// LocalDate in default timezone clock
		LocalDate nowDefault = LocalDate.now(ZoneId.systemDefault());
		System.out.println("Today's date is " + nowDefault);

		// LocalDate in UTC clock
		LocalDate nowUTC = LocalDate.now(ZoneId.of("UTC"));
		System.out.println("Today's UTC date is " + nowUTC);

		// Now LocalDate in different timezone using ZoneId
		LocalDate nowIndia = LocalDate.now(ZoneId.of("UTC+05:30"));
		System.out.println("Today's date in India is " + nowIndia);
	
					
Output:
Today's date is 2019-11-02
Today's UTC date is 2019-11-03
Today's date in India is 2019-11-03

Tag: Example for now method of class java.time.LocalDate., LocalDate now function example with arguments java.time.ZoneId zoneId, How to use now method of LocalDate?, Usage of LocalDate.now, LocalDate.now() examples, Create todays now LocalDate from any timezone., Create LocalDate using timezone instance

public static java.time.LocalDate of(int year, int month, int dayOfMonth)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, 6, 14);
		System.out.println("localDate = " + localDate);

		// Try wrong day of month. Gives exception.
		LocalDate localDateWrong = LocalDate.of(2019, 6, 50);
		System.out.println("localDateWrong = " + localDateWrong);
	
					
Output:
localDate = 2019-06-14
java.time.DateTimeException: Invalid value for DayOfMonth (valid values 1 - 28/31): 50
	at java.base/java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
	at java.base/java.time.temporal.ChronoField.checkValidValue(ChronoField.java:717)
	at java.base/java.time.LocalDate.of(LocalDate.java:270)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_of_int_int_int(LocalDateExamples.java:724)

Tag: Example for of method of class java.time.LocalDate., LocalDate of function example with arguments int year, int month, int dayOfMonth, How to use of method of LocalDate?, Usage of LocalDate.of, LocalDate.of() examples, Create LocalDate instance using year, day & month.

public static java.time.LocalDate of(int year, java.time.Month month, int dayOfMonth)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		LocalDate localDate = LocalDate.of(2019, Month.JUNE, 14);
		System.out.println("localDate = " + localDate);

		// Try wrong day of month. Gives exception.
		LocalDate localDateWrong = LocalDate.of(2019, Month.JUNE, 50);
		System.out.println("localDateWrong = " + localDateWrong);
	
					
Output:
localDate = 2019-06-14
java.time.DateTimeException: Invalid value for DayOfMonth (valid values 1 - 28/31): 50
	at java.base/java.time.temporal.ValueRange.checkValidValue(ValueRange.java:311)
	at java.base/java.time.temporal.ChronoField.checkValidValue(ChronoField.java:717)
	at java.base/java.time.LocalDate.of(LocalDate.java:250)
	at com.itsallbinary.javadocexamples.examples.java_time.LocalDateExamples.test_of_int_Month_int(LocalDateExamples.java:736)

Tag: Example for of method of class java.time.LocalDate., LocalDate of function example with arguments int year, java.time.Month month, int dayOfMonth, How to use of method of LocalDate?, Usage of LocalDate.of, LocalDate.of() examples, Create LocalDate instance using year, day & month.

public static java.time.LocalDate ofEpochDay(long epochDay)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				
		/*
		 * Epoch days = counts of days from 1970-1-1 till expected date. Rough
		 * calculation for any 2019 epoch day = number of years between 2019 & 1970 * 12
		 * months * 30 days (rough approx)
		 */
		long epochDayIn2019 = (2020 - 1970) * 12 * 30;
		LocalDate localDate2019 = LocalDate.ofEpochDay(epochDayIn2019);
		System.out.println("localDate2019 = " + localDate2019);

		// Use negative value to get local dates before epoch.
		LocalDate localDateBeforeEpoch = LocalDate.ofEpochDay(-1);
		System.out.println("localDateBeforeEpoch = " + localDateBeforeEpoch);

	
					
Output:
localDate2019 = 2019-04-14
localDateBeforeEpoch = 1969-12-31

Tag: Example for ofEpochDay method of class java.time.LocalDate., LocalDate ofEpochDay function example with arguments long epochDay, How to use ofEpochDay method of LocalDate?, Usage of LocalDate.ofEpochDay, LocalDate.ofEpochDay() examples, Create LocalDate instance using epoch day

public static java.time.LocalDate ofInstant(java.time.Instant instant, java.time.ZoneId zone)

[⿺ Javadoc] [↑ Method List] [↓ Imports]
Loading...
Usage:
				

		// Localdate from instant now & default timezone.
		LocalDate nowDefault = LocalDate.ofInstant(Instant.now(), ZoneId.systemDefault());
		System.out.println("Today's date is " + nowDefault);

		// LocalDate in UTC instant & zone
		LocalDate nowUTC = LocalDate.ofInstant(Instant.now(), ZoneId.of("UTC"));
		System.out.println("Today's UTC date is " + nowUTC);

		// Now LocalDate in different timezone using ZoneId
		LocalDate nowIndia = LocalDate.ofInstant(Instant.now(), ZoneId.of("UTC+05:30"));
		System.out.println("Today's Indian date is " + nowIndia);

	
					
Output:
Today's date is 2019-11-02
Today's UTC date is 2019-11-03
Today's Indian date is 2019-11-03

Tag: Example for ofInstant method of class java.time.LocalDate., LocalDate ofInstant function example with arguments java.time.Instant instant, java.time.ZoneId zone, How to use ofInstant method of LocalDate?, Usage of LocalDate.ofInstant, LocalDate.ofInstant() examples, Create LocalDate instance using instant & zone id

Imports

[↑ Method List]

Import statements used in examples.

				java.time.Clock
java.time.DayOfWeek
java.time.Duration
java.time.Instant
java.time.LocalDate
java.time.LocalDateTime
java.time.LocalTime
java.time.Month
java.time.OffsetDateTime
java.time.OffsetTime
java.time.Period
java.time.ZoneId
java.time.ZoneOffset
java.time.ZonedDateTime
java.time.chrono.ChronoLocalDate
java.time.chrono.IsoChronology
java.time.chrono.IsoEra
java.time.chrono.ThaiBuddhistDate
java.time.format.DateTimeFormatter
java.time.temporal.ChronoField
java.time.temporal.ChronoUnit
java.time.temporal.Temporal
java.time.temporal.TemporalAccessor
java.time.temporal.TemporalAdjuster
java.time.temporal.TemporalAmount
java.time.temporal.TemporalField
java.time.temporal.TemporalQuery
java.time.temporal.TemporalUnit
java.util.TimeZone
		

Tag: Simple working examples of methods / functions of class java.time.LocalDate along with their console output, java.time.LocalDate tutorial., Guide to java.time.LocalDate & its methods., Understanding java.time.LocalDate with examples.