Java Week Day getPreviousFriday(String date)

Here you can find the source of getPreviousFriday(String date)

Description

get Previous Friday

License

Open Source License

Declaration

public static String getPreviousFriday(String date) 

Method Source Code


//package com.java2s;

import java.text.DateFormat;

import java.text.SimpleDateFormat;
import java.util.*;

public class Main {
    public static final String dateFormat = "yyyy-MM-dd";

    public static String getPreviousFriday(String date) {
        Date d = strToDtSimpleFormat(date);
        Calendar cal = Calendar.getInstance();
        cal.setTime(d);/*from w ww  .j  a va2 s .co m*/
        cal.add(Calendar.WEEK_OF_YEAR, -1);
        cal.set(Calendar.DAY_OF_WEEK, Calendar.FRIDAY);
        return dateFormat(cal.getTime());
    }

    public static final Date strToDtSimpleFormat(String strDate) {
        if (strDate == null) {
            return null;
        }

        try {
            return getFormat(dateFormat).parse(strDate);
        } catch (Exception e) {
        }

        return null;
    }

    public static final String dateFormat(Date date) {
        if (date == null) {
            return "";
        }
        return getFormat(dateFormat).format(date);
    }

    public static final DateFormat getFormat(String format) {
        return new SimpleDateFormat(format);
    }

    public static final String format(Date date, String formate) {
        if (date == null) {
            return "";
        }
        return getFormat(formate).format(date);
    }

    public static final String format(Long dateTmie, String formate) {
        Date date = new Date(dateTmie);
        return getFormat(formate).format(date);
    }
}

Related

  1. getMondayAfter(Date date)
  2. getMondayOfThisWeek()
  3. getNextDayOfweek()
  4. getPreDay()
  5. getPreviousDay(long date, int startOfWeek)
  6. getPreviousMonday(Date date, int days)
  7. getPreviousOrNextDay(String time, int dayNum)
  8. getPreWeekLastDay()
  9. getShortWeekday(int dayOfWeek)