xuxiuxi
2017-08-01 21e08324c323d0c5d1e7cedc36323c554857a239
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package cn.com.basic.face.util;
 
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
 
public class DateUtil {
 
    private static SimpleDateFormat yyyy_MM_dd = new SimpleDateFormat("yyyy-MM-dd");
 
    private static SimpleDateFormat yyyy年MM月dd日 = new SimpleDateFormat("yyyy年MM月dd日");
 
    public static String format() {
        return yyyy_MM_dd.format(new Date());
    }
 
    public static String format(Date date) {
        return yyyy_MM_dd.format(date);
    }
 
    public static String yyyy年MM月dd日(Date date) {
        return yyyy年MM月dd日.format(date);
    }
 
    public static String yyyy年MM月dd日() {
        return yyyy年MM月dd日.format(new Date());
    }
 
    public static String yyyy_MM_dd_to_yyyy年MM月dd日(String date) {
        try {
            return yyyy年MM月dd日.format(yyyy_MM_dd.parse(date));
        } catch (Exception e) {
            return "";
        }
    }
 
    public static String getPreviousMonthLastDay() {
        Calendar aCalendar = Calendar.getInstance();
        // add -1 month to current month
        aCalendar.add(Calendar.MONTH, -1);
        // set DATE to 1, so first date of previous month
        aCalendar.set(Calendar.DATE, 1);
 
        Date firstDateOfPreviousMonth = aCalendar.getTime();
 
        // set actual maximum date of previous month
        aCalendar.set(Calendar.DATE, aCalendar.getActualMaximum(Calendar.DAY_OF_MONTH));
        //read it
        Date lastDateOfPreviousMonth = aCalendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.format(lastDateOfPreviousMonth) + " 23:59:59";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
 
    public static String getYesterday() {
        Calendar aCalendar = Calendar.getInstance();
        aCalendar.add(Calendar.DATE, -1);
 
        Date lastDateOfPreviousMonth = aCalendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        try {
            return sdf.format(lastDateOfPreviousMonth) + " 23:59:59";
        } catch (Exception e) {
            e.printStackTrace();
            return "";
        }
    }
 
}