Tuesday, December 27, 2011

Get the Week Number from a Date


<< Previous Table of Categories Next >>


 
   /**
   * Feel free to copy and use this. 
   * If you have any comments or better solutions, please paste on my blog: 
   * http://blog.yanmingyu.com or email me feedback.andrewyu@gmail.com 
 */ 
  public static int getWeekNumberFromDate(Date date) 
  {
    int week = 0;
    try
    {
      Calendar cal = Calendar.getInstance();
      cal.setTime(date);
      week = cal.get(Calendar.WEEK_OF_YEAR);
    }
    catch(Exception e){}
    return week;
  }

No comments:

Post a Comment