Java Day of Week getLastDayOfWeek(Date date)

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

Description

get Last Day Of Week

License

Apache License

Declaration

public static Date getLastDayOfWeek(Date date) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

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

public class Main {
    public static Date getLastDayOfWeek(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.SUNDAY);
        c.setTime(date);/*from  w w  w. j  a va  2 s . c  o m*/
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek() + 6); // Monday
        return c.getTime();
    }

    public static Date getFirstDayOfWeek(Date date) {
        Calendar c = new GregorianCalendar();
        c.setFirstDayOfWeek(Calendar.SUNDAY);
        c.setTime(date);
        c.set(Calendar.DAY_OF_WEEK, c.getFirstDayOfWeek()); // Monday
        return c.getTime();
    }

    public static long getTime(String s) {
        return parseMysql(s).getTime();
    }

    public static Date parseMysql(String s) {
        try {
            DateFormat fmtTemp = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            return fmtTemp.parse(s);
        } catch (ParseException e) {
            return null;
        }
    }
}

Related

  1. getISO8601WeekOfYear(Date date)
  2. getIsoDayOfWeek(Date date)
  3. getIsoWeek(java.util.Date date)
  4. getLastDayFromLastWeek(Date d)
  5. getLastDayOfTheWeek(Date date)
  6. getLastDayOfWeek(Date date)
  7. getLastDayOfWeek(Date date)
  8. getLastDayOfWeek(Date date)
  9. getLastDayOfWeek(Date date)