CodesJava

Easy learning with example program codes

Java DayOfWeek enum


Java DayOfWeek is an enum representing the 7 days of the week.

Java DayOfWeek class methods

Method Description
int get(TemporalField field) It is used to get the value of the specified field from this day-of-week as an int.
boolean isSupported(TemporalField field) It is used to check if the specified field is supported.
DayOfWeek minus(long days) It is used to return the day-of-week that is the specified number of days before this one.
DayOfWeek plus(long days) It is used to return the day-of-week that is the specified number of days after this one.
static DayOfWeek of(int dayOfWeek) It is used to obtain an instance of DayOfWeek from an int value.
static DayOfWeek[] values() It is used to return an array containing the constants of this enum type, in the order they are declared.

Example

package com.codesjava;
 
import java.time.DayOfWeek;
import java.time.LocalDate;
import java.time.Month;
import java.time.temporal.ChronoField;
 
public class TestExample {
	public static void main(String args[]){
	    LocalDate localDate = LocalDate.of(2018, Month.APRIL, 15);  
	    DayOfWeek dayOfWeek = DayOfWeek.from(localDate);  
	    System.out.println(dayOfWeek.get(ChronoField.DAY_OF_WEEK)); 
 
	    //of() method
	    DayOfWeek day = DayOfWeek.of(2);  
	    System.out.println(day.name());  
	    System.out.println(day.ordinal());  
	    System.out.println(day.getValue());
	}  
}

Output

7
TUESDAY
1
2
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