tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 Articles > Java > Coding Examples > Day of Week and Day of Month

Day of Week and Day of Month 

Find day of month and day of week from day of year.

File Name  :  
com/bethecoder/tutorials/coding/examples/DayOfMonthTest.java 
Author  :  Sudhakar KV
Email  :  [email protected]
   
package com.bethecoder.tutorials.coding.examples;

import java.util.Calendar;

public class DayOfMonthTest {

  public static void main(String[] args) {
    
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.YEAR, 2010);
    calendar.set(Calendar.DAY_OF_YEAR, 126);
    System.out.println("Calendar date : " + calendar.getTime());
    
    int dayOfMonth = calendar.get(Calendar.DAY_OF_MONTH);
    System.out.println("Day of month : " + dayOfMonth);
    
    int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
    System.out.println("Day of week : " + dayOfWeek);

    int weekOfMonth = calendar.get(Calendar.WEEK_OF_MONTH);
    System.out.println("Week of month: " + weekOfMonth);

    int weekOfYear = calendar.get(Calendar.WEEK_OF_YEAR);
    System.out.println("Week of year : " + weekOfYear);
    
  }
}
   

It gives the following output,
Calendar date : Thu May 06 12:44:39 IST 2010
Day of month : 6
Day of week : 5
Week of month: 2
Week of year : 19



 
  


  
bl  br