Java Week Day getWeekFirstDay(Date date)

Here you can find the source of getWeekFirstDay(Date date)

Description

get Week First Day

License

Open Source License

Declaration

public static Date getWeekFirstDay(Date date) 

Method Source Code

//package com.java2s;

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

public class Main {

    public static Date getWeekFirstDay(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);//from   w w w .ja v  a  2  s . com
        int year = c.get(Calendar.YEAR);
        int week = c.get(Calendar.WEEK_OF_YEAR);

        c.clear();
        c.set(Calendar.YEAR, year);
        c.set(Calendar.WEEK_OF_YEAR, week);
        c.set(Calendar.DAY_OF_WEEK, Calendar.MONDAY);
        c.setFirstDayOfWeek(Calendar.MONDAY);

        return c.getTime();
    }

    public static String getTime(Calendar c) {
        return getDate(c.getTime(), "HH:mm:ss");
    }

    public static String getDate() {
        return getDate(getCurDate(), "yyyy-MM-dd");
    }

    public static String getDate(Date date, String format) {

        String dtstr = "";
        if (date == null) {
            return dtstr;
        }

        if (format == null || "".equals(format.trim())) {
            format = "yyyy-MM-dd";
        }

        SimpleDateFormat sdf = new SimpleDateFormat(format);
        dtstr = sdf.format(date);
        return (dtstr == null ? "" : dtstr);

    }

    public static String getDate(Date date) {
        return getDate(date, "yyyy-MM-dd");
    }

    public static Date getDate(long time) {

        Calendar c = getCurCalendar();
        c.setTimeInMillis(time);

        return c.getTime();
    }

    public static Date getCurDate() {
        return getCurCalendar().getTime();
    }

    public static Calendar getCurCalendar() {
        return Calendar.getInstance();
    }
}

Related

  1. getWeekDayNUM()
  2. getWeekdayOfDateTime(String datetime)
  3. getWeekdays(DateFormatSymbols symbols)
  4. getWeekDayStr(int dayInWeek)
  5. getWeekendDays(Locale locale)
  6. isDayOfWeek(int day)
  7. isDayOfWeek(String str, int dayOfWeek)
  8. isFirseDayOfCurrentWeek(Date date)
  9. isoDayOfWeek(int javaDayOfWeek)