How do I get day of week?

Category: java.util, viewed: 15980 time(s).

In this example we want to create a calendar / date from year and day of the year, because that's all we have. Next we will find what is the day of week of the calendar object is. Let's see the example below.

package org.kodejava.example.java.util;

import java.util.Calendar;

public class DayOfYearToDayOfWeekExample 
{
    public static void main(String[] args)
    {
        // Create a calendar with year and day of year.
        Calendar calendar = Calendar.getInstance();
        calendar.set(Calendar.YEAR, 2007);
        calendar.set(Calendar.DAY_OF_YEAR, 180);
        
        // See the full information of the calendar object.
        System.out.println(calendar.getTime().toString());
        
        // Get the weekday and print it
        int weekday = calendar.get(Calendar.DAY_OF_WEEK);
        System.out.println("Weekday: " + weekday);
    }
}

Below is the result of our program.

Fri Jun 29 17:16:22 ICT 2007
Weekday: 6
Click here to lend your support to: Kode Java Org and make a donation at www.pledgie.com !

 

Can't find what you are looking for? Join our FORUMS and ask some questions!
Download Hundreds of Complimentary Industry Resources

Get hundreds of popular Industry magazines, white papers, webinars, podcasts, and more; all available at no cost to you. With more than 600 complimentary offers, you'll find plenty of titles to suit your professional interests and needs. Click Here and Sign up today!

Sponsored Links

Our Friends

Statistics

Locations of visitors to this page
visitor stats