Java Week Day getFirstDayOfWeek(String week)

Here you can find the source of getFirstDayOfWeek(String week)

Description

get First Day Of Week

License

Apache License

Declaration

public static String getFirstDayOfWeek(String week) 

Method Source Code


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

import java.text.ParseException;
import java.text.SimpleDateFormat;

import java.util.Date;

public class Main {
    private static final String LEGACY_FORMAT = "MM/dd/yyyy HH:mm aa";

    public static String getFirstDayOfWeek(String week) {
        try {//  w  w  w.  ja va 2 s.  c o m
            return getDefaultDateFormat().format(getDefaultWeekFormat().parse(week));
        } catch (ParseException e) {
            return "ERROR_DAY";
        }
    }

    public static String format(Date date, String formatPattern) {
        if (date == null) {
            return "";
        } else {
            return new SimpleDateFormat(formatPattern).format(date);
        }
    }

    public static SimpleDateFormat getDefaultDateFormat() {
        return new SimpleDateFormat("yyyyMMdd");
    }

    public static Date parse(String s, String formatPattern) {
        try {
            return new SimpleDateFormat(formatPattern).parse(s);
        } catch (ParseException e) {
            throw new RuntimeException("could not parse date: " + s + " LEGACY_FORMAT = "
                    + new SimpleDateFormat(LEGACY_FORMAT).toPattern(), e);
        }
    }

    public static SimpleDateFormat getDefaultWeekFormat() {
        return new SimpleDateFormat("yyyyww");
    }
}

Related

  1. getFirstDayOfWeek(Date date)
  2. getFirstDayOfWeek(final Date date)
  3. getFirstDayOfWeek(String format)
  4. getFirstDayOfWeek(String str, int week)
  5. getFirstDayOfWeek(String week)
  6. getFriday(Date date)
  7. getLastDayOfCurrWeek()
  8. getLastDayOfWeek(int year, int month)
  9. getLastSundayBeforeThisWeek()