Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,890 questions

51,817 answers

573 users

How to determine day of week from specified date in Java

4 Answers

0 votes
import java.util.Calendar;

public class MyClass {
    public static void main(String args[]) {
        Calendar cal = Calendar.getInstance();

        cal.set(2022, 2, 17); // 17/3/2022
        
        int dayOfWeek = cal.get(Calendar.DAY_OF_WEEK);
        
        System.out.println(dayOfWeek);
    }
}
    
    
    
    
/*
run:
    
5
    
*/

 



answered Mar 7, 2022 by avibootz
0 votes
import java.util.Calendar;
 
public class MyClass {
    public static void main(String args[]) {
        Calendar calendar = Calendar.getInstance();
        
        calendar.set(2023, Calendar.OCTOBER, 24);  

        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); 
         
        System.out.println(dayOfWeek);
    }
}
     
     
     
     
/*
run:
     
3
     
*/

 



answered Oct 24, 2023 by avibootz
0 votes
import java.util.Calendar;
 
public class MyClass {
    public static void main(String args[]) {
        Calendar calendar = Calendar.getInstance();
        
        calendar.set(2023, Calendar.OCTOBER, 24);  
        
        int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK); 

        String[] daysOfWeek = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        String dayOfWeekName = daysOfWeek[dayOfWeek - Calendar.SUNDAY]; 
         
        System.out.println(dayOfWeekName);
    }
}
     
     
     
     
/*
run:

Tuesday
     
*/

 



answered Oct 24, 2023 by avibootz
0 votes
import java.time.DayOfWeek;
import java.time.LocalDate;
 
public class MyClass {
    public static void main(String args[]) {

        LocalDate date = LocalDate.of(2023, 10, 24);  
        DayOfWeek dayOfWeek = date.getDayOfWeek();
         
        System.out.println(dayOfWeek);
    }
}
     
     
     
     
/*
run:

TUESDAY
     
*/

 



answered Oct 24, 2023 by avibootz

Related questions

1 answer 131 views
1 answer 161 views
2 answers 231 views
231 views asked Oct 30, 2016 by avibootz
1 answer 232 views
1 answer 122 views
...