CodesJava

Easy learning with example program codes

Java 8 OffsetDateTime class


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

Java OffsetDateTime class methods

Method Description
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.codesjava;
 
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
Posted in Date   


Industrial Training

We offers Placement Oriented Training on Java, Spring, JSF, Hibernate, PHP, AngularJS, Angular 4, PLSQL, Oracle BI Publisher etc. We also provides Online training, please mail us at hr@codesjava.com.

Development

We also provides the Development services for Website Development , Java Development, PHP Development, Android App Development etc. You can contact us on hr@codesjava.com.

Copyright © 2019 CodesJava DMCA.com Protection Status SiteMap Reference: Java Wiki