Java Year Day getWeekNumOfYearDay(String strDate)

Here you can find the source of getWeekNumOfYearDay(String strDate)

Description

get Week Num Of Year Day

License

Apache License

Declaration

public static int getWeekNumOfYearDay(String strDate) throws ParseException 

Method Source Code

//package com.java2s;
/*//www  .ja v  a  2 s .com
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static int getWeekNumOfYearDay(String strDate) throws ParseException {
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd");
        Date curDate = format.parse(strDate);
        int iWeekNum;
        calendar.setTime(curDate);
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1;
        } else {
            iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
        }
        return iWeekNum;
    }

    public static int getWeekNumOfYearDay(Date curDate) {
        if (curDate == null)
            return 0;
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(curDate);
        int iWeekNum;
        if (calendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY) {
            iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR) - 1;
        } else {
            iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
        }
        // int iWeekNum = calendar.get(Calendar.WEEK_OF_YEAR);
        return iWeekNum;
    }
}

Related

  1. getFirstDayOfThisYear()
  2. getLastDayOfTheYear(int year)
  3. getLastDayOfYear(int year)
  4. getLastDayOfYear(int year)
  5. getTodayYear()
  6. getYearFirstDay(String date)
  7. getYearLastDay(String dateString)
  8. getYearWeek(String curday)
  9. getYearWeek(String curday)