- java.time Package Classes
- java.time - Home
- java.time - Clock
- java.time - Duration
- java.time - Instant
- java.time - LocalDate
- java.time - LocalDateTime
- java.time - LocalTime
- java.time - MonthDay
- java.time - OffsetDateTime
- java.time - OffsetTime
- java.time - Period
- java.time - Year
- java.time - YearMonth
- java.time - ZonedDateTime
- java.time - ZoneId
- java.time - ZoneOffset
- java.time Package Enums
- java.time - Month
- java.time Useful Resources
- java.time - Discussion
java.time.Month.getLong() Method Example
Description
The java.time.Month.getLong(TemporalField field) method gets the value of the specified field from this Month as an long.
Declaration
Following is the declaration for java.time.Month.getLong(TemporalField field) method.
public int get(TemporalField field)
Parameters
field − the field to get, not null.
Return Value
the value for the field.
Exceptions
DateTimeException − if a value for the field cannot be obtained or the value is outside the range of valid values for the field.
UnsupportedTemporalTypeException − if the field is not supported or the range of values exceeds an long.
ArithmeticException − if numeric overflow occurs.
Example
The following example shows the usage of java.time.Month.getLong(TemporalField field) method.
package com.tutorialspoint; import java.time.Month; import java.time.temporal.ChronoField; public class MonthDemo { public static void main(String[] args) { Month day = Month.FEBRUARY; System.out.println(day.getLong(ChronoField.MONTH_OF_YEAR)); } }
Let us compile and run the above program, this will produce the following result −
2
Advertisements