Java Month Day getMonthFristWeekSunday(String month)

Here you can find the source of getMonthFristWeekSunday(String month)

Description

get Month Frist Week Sunday

License

Apache License

Declaration

public static Date getMonthFristWeekSunday(String month) 

Method Source Code


//package com.java2s;
/*/*w w w. j  av a  2s. co  m*/
Copyright  DR.YangLong
    
Licensed 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.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class Main {

    public static Date getMonthFristWeekSunday(String month) {
        Calendar c = Calendar.getInstance();
        c.setTime(parse(month, "yyyy-MM"));
        c.set(Calendar.DATE, 1);
        int dayNum = c.get(Calendar.DAY_OF_WEEK);
        c.add(Calendar.DATE, 1 - dayNum);
        return c.getTime();
    }

    public static Date parse(String dateString) {
        return parse(dateString, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date parse(String dateString, String pattern) {
        DateFormat df = new SimpleDateFormat(pattern);
        Date date = null;
        try {
            date = df.parse(dateString);
        } catch (Throwable t) {
            date = null;
        }
        return date;
    }
}

Related

  1. getMonthFirstDay()
  2. getMonthFirstDay()
  3. getMonthFirstDay(Date date)
  4. getMonthFirstDay(String date)
  5. getMonthFirstDay(T date)
  6. getMonthLastDay()
  7. getMonthLastDay()
  8. getMonthLastDay()
  9. getMonthLastDay(String curmonth, int month)