- 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.LocalDateTime.of() Method Example
Description
The java.time.LocalDateTime.of(int year, Month month, int dayOfMonth, int hour, int minute, int second) method obtains an instance of LocalDateTime from year, month, day, hour, minute and second, setting the nanosecond to zero.
Declaration
Following is the declaration for java.time.LocalDateTime.of(int year, Month month, int dayOfMonth, int hour, int minute, int second) method.
public static LocalDateTime of(int year, int month, int dayOfMonth, Month hour, int minute, int second)
Parameters
year − the year to represent, from MIN_YEAR to MAX_YEAR
month − the month-of-year to represent
dayOfMonth − the day-of-month to represent, from 1 to 31
hour − the hour-of-day to represent, from 0 to 23
minute − the minute-of-hour to represent, from 0 to 59
second − the second-of-minute to represent, from 0 to 59
Return Value
the local date-time, not null.
Exceptions
DateTimeException − if the value of any field is out of range, or if the day-of-month is invalid for the month-year.
Example
The following example shows the usage of java.time.LocalDateTime.of(int year, Month month, int dayOfMonth, int hour, int minute, int second) method.
package com.tutorialspoint; import java.time.LocalDateTime; import java.time.Month; public class LocalDateTimeDemo { public static void main(String[] args) { LocalDateTime date = LocalDateTime.of(2017,Month.FEBRUARY,3,6,30,40); System.out.println(date); } }
Let us compile and run the above program, this will produce the following result −
2017-02-03T06:30:40
To Continue Learning Please Login
Login with Google