DateUtils.java
2.55 KB
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
74
package cn.com.glsx.dj.taskcenter.util;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.temporal.TemporalAdjusters;
import java.util.Calendar;
import java.util.Date;
public class DateUtils extends cn.com.glsx.framework.core.util.DateUtils {
private static DateFormat dateFormat= new SimpleDateFormat(DATE_FORMAT);
public static Integer getMonthInt(Date date){
Calendar now = Calendar.getInstance();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
now.setTime(dateFormat.parse(formatDate(date)));
int month = now.get(2) + 1;
return month;
} catch (ParseException var4) {
var4.printStackTrace();
return null;
}
}
public static Integer getYearInt(Date date) {
Calendar cl = Calendar.getInstance();
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
try {
cl.setTime(dateFormat.parse(formatDate(date)));
return cl.get(1);
} catch (ParseException var3) {
var3.printStackTrace();
return 0;
}
}
/**
*
* @Description: 获取当月开始时间 yyyy-MM-01 00:00:00
* @param yearMonth yyyy-MM
* @return
*/
public static String getMonthFirstTime(String yearMonth) {
return yearMonth.concat("-01 00:00:00");
}
/**
*
* @Description: 获取当月开始时间 yyyy-MM-(28-31) 23:59:59
* @param yearMonth yyyy-MM
* @return
*/
public static String getMonthEndtTime(String yearMonth) {
Date date = parseDate(getMonthFirstTime(yearMonth), "yyyy-MM-dd HH:mm:ss");
return getOffsetDate(getOffsetDate(date, 1, Calendar.MONTH), -1,Calendar.SECOND,"yyyy-MM-dd HH:mm:ss");
}
/**
* 获取当前月的第一天
*/
public static Date getFirstDayCurrentMonth() {
LocalDateTime firstDayOfMonth = LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth())), LocalTime.MIN);
return Date.from(firstDayOfMonth.atZone(ZoneId.systemDefault()).toInstant());
}
public static Date getLastDayCurrentMonth() {
LocalDateTime lastDayOfMonth = LocalDateTime.of(LocalDate.from(LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth())), LocalTime.MAX);
return Date.from(lastDayOfMonth.atZone(ZoneId.systemDefault()).toInstant());
}
}