public final class DateTimeUtil {
private DateTimeUtil() {
super();
}
public static LocalDateTime getUtcLongTime(Long time) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneOffset.UTC);
}
public static LocalDateTime getLocalLongTime(Long time) {
return LocalDateTime.ofInstant(Instant.ofEpochMilli(time), ZoneId.systemDefault());
}
public static Long timeToLong(String time, ZoneId zoneId) {
LocalDateTime localDateTime = LocalDateTime.parse(time, DateTimeFormatter.ISO_LOCAL_DATE_TIME);
return LocalDateTime.from(localDateTime).atZone(zoneId).toInstant().truncatedTo(ChronoUnit.SECONDS).toEpochMilli();
}
public static String toUtcTimeString(Long time) {
return getUtcLongTime(time).truncatedTo(ChronoUnit.SECONDS).format(DateTimeFormatter.ISO_LOCAL_DATE_TIME);
}
public static Long localDateTimeMillis(LocalDateTime localDateTime) {
return localDateTime.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
public static long getTimeMills() {
LocalDate localDate = LocalDate.now();
LocalTime localTime = LocalTime.now();
return LocalDateTime.of(localDate.getYear(), localDate.getMonth(), localDate.getDayOfMonth(), localTime.getHour(), localTime.getMinute(), 0)
.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
}
public static String toMinuteString(Long longTime) {
LocalDateTime localDateTime =
LocalDateTime.ofInstant(Instant.ofEpochMilli(longTime), ZoneId.systemDefault());
return localDateTime.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"));
}
public static Date changeTimeMills(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTime();
}
public static Map<String, Long> getToday() {
LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), LocalTime.MIN);
LocalDateTime today_end = LocalDateTime.of(LocalDate.now(), LocalTime.MAX);
Map<String, Long> map = new HashMap<>();
map.put("todayStart", today_start.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
map.put("todayEnd", today_end.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli());
return map;
}
public static Map<String, Long> createTimeRange(Long collection) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
Long endTime = calendar.getTime().getTime();
calendar.add(Calendar.MINUTE, (int) -collection);
Long startTime = calendar.getTime().getTime();
Map<String, Long> map = new HashMap<>();
map.put("startTime", startTime);
map.put("endTime", endTime);
return map;
}
public static int getCurrentYear() {
LocalDateTime currentDate = LocalDateTime.now();
return currentDate.getYear();
}
public static TimeRangeVo getTodayTimeRange(Long startHour) {
LocalTime start = LocalTime.of(Math.toIntExact(startHour), 0);
LocalDateTime today_start = LocalDateTime.of(LocalDate.now(), start);
long beginTime = today_start.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
LocalDateTime today_end;
TimeRangeVo lastHourTimeRange = getLastHourTimeRange();
if (lastHourTimeRange.getBeginTime() < beginTime) {
beginTime = today_start.plusDays(-1).atZone(ZoneId.systemDefault()).toInstant().toEpochMilli();
today_end = today_start;
} else {
today_end = today_start.plusDays(1);
}
long endTime = today_end.atZone(ZoneId.systemDefault()).toInstant().toEpochMilli() - 1;
return new TimeRangeVo(beginTime, endTime);
}
public static TimeRangeVo getLastHourTimeRange() {
LocalDateTime localDateTime = LocalDateTime.now().toLocalDate().atTime(LocalDateTime.now().plusHours(-1).getHour(), 0, 0);
Long beginTime = localDateTimeMillis(localDateTime);
Long endTime = localDateTimeMillis(localDateTime.plusHours(1));
return new TimeRangeVo(beginTime, endTime);
}
public static String beautifyTime(Long time) {
if (time == null) {
return "--";
}
if (time == 0) return "0秒";
boolean negative = false;
if (time < 0) {
time = -time;
negative = true;
}
;
long second = time / 1000;
long days = second / (60 * 60 * 24);
long hours = (second % (60 * 60 * 24)) / (60 * 60);
long minutes = (second % (60 * 60)) / 60;
long seconds = second % 60;
StringBuilder stringBuffer = new StringBuilder();
if(days!=0)
{
stringBuffer.append(days).append("天");
}
if(hours!=0)
{
stringBuffer.append(hours).append("小时");
}
if(minutes!=0)
{
stringBuffer.append(minutes).append("分钟");
}
if(seconds!=0)
{
stringBuffer.append(seconds).append("秒");
}
String strTime = stringBuffer.toString();
if (negative) {
return "-" + strTime;
}
return strTime;
}
public static Long queryZeroPointOfDay(Long time){
Calendar calendar = Calendar.getInstance();
calendar.setTime(new Date(time));
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar.getTimeInMillis();
}
}
public static String localToUTC(Long localTime, Boolean isString) {
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(localTime);
int zoneOffset = calendar.get(Calendar.ZONE_OFFSET);
int dstOffset = calendar.get(Calendar.DST_OFFSET);
calendar.add(Calendar.MILLISECOND, -(zoneOffset + dstOffset));
if (isString) {
return DateFormatThread.simpleDateFormatExpression.get().format(calendar.getTime());
} else {
return calendar.getTimeInMillis() + "";
}
}
public static Long calculateDate(Integer dateLogo, Date time, Integer size) {
Calendar instance = Calendar.getInstance();
instance.setTime(time);
instance.add(dateLogo, size);
return instance.getTime().getTime();
}
public static DateDetailsModel getDateDetail(Long time) {
DateDetailsModel dateDetailsModel = new DateDetailsModel();
dateDetailsModel.setTime(new Date(time));
Calendar instance = Calendar.getInstance();
instance.setTime(dateDetailsModel.getTime());
dateDetailsModel.setYear(instance.get(Calendar.YEAR));
dateDetailsModel.setMonth(instance.get(Calendar.MONTH) + 1);
dateDetailsModel.setDay(instance.get(Calendar.DAY_OF_MONTH));
dateDetailsModel.setHour(instance.get(Calendar.HOUR_OF_DAY));
dateDetailsModel.setMin(instance.get(Calendar.MINUTE));
dateDetailsModel.setSecond(instance.get(Calendar.SECOND));
return dateDetailsModel;
}
public static TimeRangeVo getLastMonth() {
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.MONTH, -1);
calendar.set(Calendar.DAY_OF_MONTH, calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
calendar.set(Calendar.HOUR_OF_DAY, 0);
long startTime = calendar.getTime().getTime();
calendar.add(Calendar.MONTH, 1);
long endTime = calendar.getTime().getTime();
return new TimeRangeVo(startTime, endTime);
}
public static List<TimeRangeVo> splitCurrentMonth(TimeRangeVo timeRangeVo) {
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
long lastMonth = calendar.getTime().getTime();
List<TimeRangeVo> list = new ArrayList<>();
if (timeRangeVo.getBeginTime() < lastMonth && timeRangeVo.getEndTime() > lastMonth) {
list.add(new TimeRangeVo(timeRangeVo.getBeginTime(), lastMonth));
list.add(new TimeRangeVo(lastMonth, timeRangeVo.getEndTime()));
return list;
}
list.add(timeRangeVo);
return list;
}
public static List<TimeRangeVo> splitMonth(TimeRangeVo timeRangeVo) {
List<TimeRangeVo> resultList = new ArrayList<>();
long beginTime = timeRangeVo.getBeginTime();
long endTime = timeRangeVo.getEndTime();
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(beginTime);
long aStart = beginTime;
long aEnd = beginTime;
while (calendar.getTimeInMillis() < endTime) {
calendar.add(Calendar.MONTH, 1);
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.add(Calendar.DATE, -1);
calendar.set(Calendar.HOUR_OF_DAY, 23);
calendar.set(Calendar.MINUTE, 59);
calendar.set(Calendar.SECOND, 59);
if (calendar.getTimeInMillis() >= endTime) {
aEnd = endTime;
resultList.add(new TimeRangeVo(aStart, aEnd));
break;
}
calendar.add(Calendar.DATE, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
aEnd = calendar.getTimeInMillis();
resultList.add(new TimeRangeVo(aStart, aEnd));
aStart=aEnd;
}
return resultList;
}
public static Calendar queryMonthZero(Calendar calendar) {
calendar.set(Calendar.DAY_OF_MONTH, 1);
calendar.set(Calendar.HOUR_OF_DAY, 0);
calendar.set(Calendar.MINUTE, 0);
calendar.set(Calendar.SECOND, 0);
calendar.set(Calendar.MILLISECOND, 0);
return calendar;
}
dateSpiltUtil
public class DateSplitUtil {
private final static SimpleDateFormat shortSdf = new SimpleDateFormat("yyyy-MM-dd");
private final static SimpleDateFormat longHourSdf = new SimpleDateFormat("yyyy-MM-dd HH");
private final static SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
private final static SimpleDateFormat longSdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
public static String toStr(String format, Date time) {
SimpleDateFormat df = null;
if (null == format) {
df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
} else {
df = new SimpleDateFormat(format);
}
try {
return df.format(time);
} catch (Exception e) {
return null;
}
}
public static Date toDate(String source) {
String formatString = "yyyy-MM-dd hh:mm:ss";
if (source == null || "".equals(source.trim())) {
return null;
}
source = source.trim();
if (source.matches("^\\d{4}$")) {
formatString = "yyyy";
} else if (source.matches("^\\d{4}-\\d{1,2}$")) {
formatString = "yyyy-MM";
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2}$")) {
formatString = "yyyy-MM-dd";
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}$")) {
formatString = "yyyy-MM-dd hh";
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}$")) {
formatString = "yyyy-MM-dd hh:mm";
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}$")) {
formatString = "yyyy-MM-dd hh:mm:ss";
} else if (source.matches("^\\d{4}-\\d{1,2}-\\d{1,2} {1}\\d{1,2}:\\d{1,2}:\\d{1,2}\\.\\d{1,3}$")) {
formatString = "yyyy-MM-dd HH:mm:ss.SSS";
}
try {
SimpleDateFormat sdf = new SimpleDateFormat(formatString);
Date date = sdf.parse(source);
return date;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static Date getHourStartTime(Date date) {
Date dt = null;
try {
dt = longHourSdf.parse(longHourSdf.format(date));
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getHourEndTime(Date date) {
Date dt = null;
try {
dt = longSdf.parse(longHourSdf.format(date) + ":59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getDayStartTime(Date date) {
Date dt = null;
try {
dt = shortSdf.parse(shortSdf.format(date));
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getDayEndTime(Date date) {
Date dt = null;
try {
dt = longSdf.parse(shortSdf.format(date) + " 23:59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static int getWeekDay(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int week_of_year = c.get(Calendar.DAY_OF_WEEK);
return week_of_year - 1;
}
public static Date getWeekStartTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
try {
int weekday = c.get(Calendar.DAY_OF_WEEK) - 2;
c.add(Calendar.DATE, -weekday);
c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00.000"));
} catch (Exception e) {
e.printStackTrace();
}
return c.getTime();
}
public static Date getWeekEndTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
try {
int weekday = c.get(Calendar.DAY_OF_WEEK);
c.add(Calendar.DATE, 8 - weekday);
c.setTime(longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999"));
} catch (Exception e) {
e.printStackTrace();
}
return c.getTime();
}
public static Date getMonthStartTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date dt = null;
try {
c.set(Calendar.DATE, 1);
dt = shortSdf.parse(shortSdf.format(c.getTime()));
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getMonthEndTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date dt = null;
try {
c.set(Calendar.DATE, 1);
c.add(Calendar.MONTH, 1);
c.add(Calendar.DATE, -1);
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getYearStartTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date dt = null;
try {
c.set(Calendar.MONTH, 0);
c.set(Calendar.DATE, 1);
dt = shortSdf.parse(shortSdf.format(c.getTime()));
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getYearEndTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
Date dt = null;
try {
c.set(Calendar.MONTH, 11);
c.set(Calendar.DATE, 31);
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getQuarterStartTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int currentMonth = c.get(Calendar.MONTH) + 1;
Date dt = null;
try {
if (currentMonth >= 1 && currentMonth <= 3)
c.set(Calendar.MONTH, 0);
else if (currentMonth >= 4 && currentMonth <= 6)
c.set(Calendar.MONTH, 3);
else if (currentMonth >= 7 && currentMonth <= 9)
c.set(Calendar.MONTH, 6);
else if (currentMonth >= 10 && currentMonth <= 12)
c.set(Calendar.MONTH, 9);
c.set(Calendar.DATE, 1);
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00.000");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getQuarterEndTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int currentMonth = c.get(Calendar.MONTH) + 1;
Date dt = null;
try {
if (currentMonth >= 1 && currentMonth <= 3) {
c.set(Calendar.MONTH, 2);
c.set(Calendar.DATE, 31);
} else if (currentMonth >= 4 && currentMonth <= 6) {
c.set(Calendar.MONTH, 5);
c.set(Calendar.DATE, 30);
} else if (currentMonth >= 7 && currentMonth <= 9) {
c.set(Calendar.MONTH, 8);
c.set(Calendar.DATE, 30);
} else if (currentMonth >= 10 && currentMonth <= 12) {
c.set(Calendar.MONTH, 11);
c.set(Calendar.DATE, 31);
}
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getHalfYearStartTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int currentMonth = c.get(Calendar.MONTH) + 1;
Date dt = null;
try {
if (currentMonth >= 1 && currentMonth <= 6) {
c.set(Calendar.MONTH, 0);
} else if (currentMonth >= 7 && currentMonth <= 12) {
c.set(Calendar.MONTH, 6);
}
c.set(Calendar.DATE, 1);
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 00:00:00.000");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static Date getHalfYearEndTime(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int currentMonth = c.get(Calendar.MONTH) + 1;
Date dt = null;
try {
if (currentMonth >= 1 && currentMonth <= 6) {
c.set(Calendar.MONTH, 5);
c.set(Calendar.DATE, 30);
} else if (currentMonth >= 7 && currentMonth <= 12) {
c.set(Calendar.MONTH, 11);
c.set(Calendar.DATE, 31);
}
dt = longSdf.parse(shortSdf.format(c.getTime()) + " 23:59:59.999");
} catch (Exception e) {
e.printStackTrace();
}
return dt;
}
public static int getTenDay(Date date) {
Calendar c = Calendar.getInstance();
c.setTime(date);
int i = c.get(Calendar.DAY_OF_MONTH);
if (i < 11)
return 1;
else if (i < 21)
return 2;
else
return 3;
}
public static Date getTenDayStartTime(Date date) {
int ten = getTenDay(date);
try {
if (ten == 1) {
return getMonthStartTime(date);
} else if (ten == 2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-11");
return shortSdf.parse(df.format(date));
} else {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-21");
return shortSdf.parse(df.format(date));
}
} catch (ParseException e) {
e.printStackTrace();
}
return date;
}
public static Date getTenDayEndTime(Date date) {
int ten = getTenDay(date);
try {
if (ten == 1) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-10 23:59:59.999");
return longSdf.parse(df.format(date));
} else if (ten == 2) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-20 23:59:59.999");
return longSdf.parse(df.format(date));
} else {
return getMonthEndTime(date);
}
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
public static int getYearDayIndex(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
return calendar.get(Calendar.DAY_OF_YEAR);
}
public static int getYearWeekIndex(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setFirstDayOfWeek(Calendar.MONDAY);
calendar.setTime(date);
return calendar.get(Calendar.WEEK_OF_YEAR);
}
public static int getYearMonthIndex(Date date) {
Calendar calendar = Calendar.getInstance();
calendar.setTime(date);
return calendar.get(Calendar.MONTH) + 1;
}
public static int getYeartQuarterIndex(Date date) {
int month = getYearMonthIndex(date);
if (month <= 3)
return 1;
else if (month <= 6)
return 2;
else if (month <= 9)
return 3;
else
return 4;
}
public static List<Date[]> yearDayList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getYearStartTime(date);
Date endtm = getYearEndTime(date);
calendar.setTime(starttm);
while (calendar.getTime().before(endtm)) {
Date st = getDayStartTime(calendar.getTime());
Date et = getDayEndTime(calendar.getTime());
result.add(new Date[]{st, et});
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
return result;
}
public static List<Date[]> yearWeekList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getYearStartTime(date);
Date endtm = getYearEndTime(date);
calendar.setTime(starttm);
calendar.setFirstDayOfWeek(Calendar.MONDAY);
while (calendar.getTime().before(endtm)) {
Date st = getWeekStartTime(calendar.getTime());
Date et = getWeekEndTime(calendar.getTime());
result.add(new Date[]{st, et});
calendar.add(Calendar.WEEK_OF_YEAR, 1);
}
return result;
}
public static List<Date[]> yearMonthList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getYearStartTime(date);
Date endtm = getYearEndTime(date);
calendar.setTime(starttm);
while (calendar.getTime().before(endtm)) {
Date tm = calendar.getTime();
Date st = getMonthStartTime(tm);
Date et = getMonthEndTime(tm);
result.add(new Date[]{st, et});
calendar.add(Calendar.MONTH, 1);
}
return result;
}
public static List<Date[]> yearQuarterList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getYearStartTime(date);
Date endtm = getYearEndTime(date);
calendar.setTime(starttm);
while (calendar.getTime().before(endtm)) {
Date st = getQuarterStartTime(calendar.getTime());
Date et = getQuarterEndTime(calendar.getTime());
result.add(new Date[]{st, et});
calendar.add(Calendar.MONTH, 3);
}
return result;
}
public static List<Date[]> monthTenDayList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getMonthStartTime(date);
Date endtm = getMonthEndTime(date);
calendar.setTime(starttm);
while (calendar.getTime().before(endtm)) {
Date st = getTenDayStartTime(calendar.getTime());
Date et = getTenDayEndTime(calendar.getTime());
result.add(new Date[]{st, et});
calendar.add(Calendar.DAY_OF_MONTH, 11);
}
return result;
}
public static List<Date[]> yearTenDayList(Date date) {
List<Date[]> result = new ArrayList<>();
Calendar calendar = Calendar.getInstance();
Date starttm = getYearStartTime(date);
Date endtm = getYearEndTime(date);
calendar.setTime(starttm);
while (calendar.getTime().before(endtm)) {
result.addAll(monthTenDayList(calendar.getTime()));
calendar.add(Calendar.MONTH, 1);
}
return result;
}
private static void test() {
Date date = new Date();
System.out.println("当前小时开始:" + toStr(null, getHourStartTime(date)));
System.out.println("当前小时结束:" + toStr(null, getHourEndTime(date)));
System.out.println("当前天开始:" + toStr(null, getDayStartTime(date)));
System.out.println("当前天时结束:" + toStr(null, getDayEndTime(date)));
System.out.println("当前天是星期:" + getWeekDay(date));
System.out.println("当前周开始:" + toStr(null, getWeekStartTime(date)));
System.out.println("当前周结束:" + toStr(null, getWeekEndTime(date)));
System.out.println("当前月开始:" + toStr(null, getMonthStartTime(date)));
System.out.println("当前月结束:" + toStr(null, getMonthEndTime(date)));
System.out.println("当前季度开始:" + toStr(null, getQuarterStartTime(date)));
System.out.println("当前季度结束:" + toStr(null, getQuarterEndTime(date)));
System.out.println("当前半年/后半年开始:" + toStr(null, getHalfYearStartTime(date)));
System.out.println("当前半年/后半年结束:" + toStr(null, getHalfYearEndTime(date)));
System.out.println("当前年开始:" + toStr(null, getYearStartTime(date)));
System.out.println("当前年结束:" + toStr(null, getYearEndTime(date)));
System.out.println("当前属于本年第:" + getYearDayIndex(date) + "天");
System.out.println("当前属于本年第:" + getYearWeekIndex(date) + "周");
System.out.println("当前属于本年第:" + getYearMonthIndex(date) + "月");
System.out.println("当前属于本年第:" + getYeartQuarterIndex(date) + "季度");
System.out.println("时间转换(yyyy): " + toStr(null, toDate("2018")));
System.out.println("时间转换(yyyy-MM): " + toStr(null, toDate("2018-01")));
System.out.println("时间转换(yyyy-MM-dd): " + toStr(null, toDate("2018-01-01")));
System.out.println("时间转换(yyyy-MM-dd hh): " + toStr(null, toDate("2018-01-01 23")));
System.out.println("时间转换(yyyy-MM-dd hh:mm): " + toStr(null, toDate("2018-01-01 23:59")));
System.out.println("时间转换(yyyy-MM-dd hh:mm:ss): " + toStr(null, toDate("2018-01-01 23:59:59")));
System.out.println("时间转换(yyyy-MM-dd HH:mm:ss.SSS): " + toStr(null, toDate("2018-01-01 23:59:59.999")));
}
private static void testYearDayList() {
List<Date[]> datas = yearDayList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一年的日期列表)第" + (i + 1) + "天:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
private static void testYearWeekList() {
List<Date[]> datas = yearWeekList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一年的周列表)第" + (i + 1) + "周:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
private static void testYearQuarterList() {
List<Date[]> datas = yearQuarterList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一年的季度列表)第" + (i + 1) + "季度:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
private static void testYearMonthList() {
List<Date[]> datas = yearMonthList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一年的月列表)第" + (i + 1) + "月:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
private static void testMonthTenDayList() {
List<Date[]> datas = monthTenDayList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一月的旬列表)第" + (i % 3 + 1) + "旬:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
private static void testyearTenDayList() {
List<Date[]> datas = yearTenDayList(new Date());
for (int i = 0; i < datas.size(); i++) {
Date[] date = datas.get(i);
System.out.println("(一年的旬列表)第" + (i / 3 + 1) + "月" + (i % 3 + 1) + "旬:" + sdf.format(date[0]) + " " + sdf.format(date[1]));
}
}
public static void main(String[] args) {
test();
testYearDayList();
testYearWeekList();
testYearMonthList();
testYearQuarterList();
testyearTenDayList();
testMonthTenDayList();
}
}