Java Week getPreWeekDayByStr(String curday)

Here you can find the source of getPreWeekDayByStr(String curday)

Description

get Pre Week Day By Str

License

Apache License

Declaration

public static String getPreWeekDayByStr(String curday) 

Method Source Code


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

import java.text.SimpleDateFormat;

import java.util.*;

public class Main {
    static public SimpleDateFormat yyyyMMdd = new SimpleDateFormat("yyyy-MM-dd");

    public static String getPreWeekDayByStr(String curday) {
        try {//  w ww .ja v a 2s.co  m
            java.util.Date date = str2date(curday);
            /*            Calendar rightNow = Calendar.getInstance();
                    rightNow.setTime(date);
                    int week = rightNow.get(Calendar.DAY_OF_WEEK);
                    if (week == 0) week = 1;
                    if (week == 7) week = 8;*/
            return getDateStr(new java.util.Date(date.getTime() - 7 * 24 * 3600 * 1000));
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static Date str2date(String str) {
        Date result = null;
        try {
            Date udate = yyyyMMdd.parse(str);
            result = new Date(udate.getTime());
            return result;
        } catch (Exception e) {
            e.printStackTrace();
            return null;
        }
    }

    public static String getDateStr(java.util.Date date) {
        if (date == null)
            return "";
        try {
            return yyyyMMdd.format(date);
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }

    public static String getTime(String parrten) {
        String timestr;
        if (parrten == null || parrten.equals("")) {
            parrten = "yyyyMMddHHmmss";
        }
        java.text.SimpleDateFormat sdf = new SimpleDateFormat(parrten);
        java.util.Date cday = new java.util.Date();
        timestr = sdf.format(cday);
        return timestr;
    }
}

Related

  1. currentWeekEndDate()
  2. getNextWeek(String week)
  3. getPreWeek(String week)
  4. getPreWeekDayByStr(String curday)
  5. getPreWeeks(int weekNum)
  6. getStartDate(Date date, int weeks, Locale locale)
  7. getStartDateOfWeek(Date selectedDate, Locale locale)