Java 8 OffsetDateTime class

The java.util.OffsetDateTime class is an immutable representation of a date-time with an offset.

Java OffsetDateTime class methods

MethodDescription
int get(TemporalField field)It is used to get the value of the specified field from this date-time as an int.
int getDayOfMonth()It is used to get the day-of-month field.
iint getDayOfYear()It is used to get the day-of-year field.
DayOfWeek getDayOfWeek()It is used to get the day-of-week field, which is an enum DayOfWeek.
OffsetDateTime minusDays(long days)It is used to return a copy of this OffsetDateTime with the specified number of days subtracted.
static OffsetDateTime now()It is used to obtain the current date-time from the system clock in the default time-zone.
OffsetDateTime plusDays(long days)It is used to return a copy of this OffsetDateTime with the specified number of days added.
LocalDate toLocalDate()It is used to get the LocalDate part of this date-time.

Example

package com.w3spoint;
 
import java.time.OffsetDateTime;
 
public class TestExample {
  public static void main(String args[]){
	OffsetDateTime offsetDT = OffsetDateTime.now(); 
	//Day of month
        System.out.println(offsetDT.getDayOfMonth());
 
        //Day of year
        System.out.println(offsetDT.getDayOfYear()); 
 
        //Day of week
        System.out.println(offsetDT.getDayOfWeek());         
  }  
}

Output

15
105
SUNDAY
Content Protection by DMCA.com
Please Share