对当前时间格式化:
public static long getCurrentTimeMillis(String pattern) {
return Long.valueOf(toString(LocalDateTime.now(), pattern));
}
对指定日期进行格式化:
public static LocalDate toLocalDate(String date, String pattern) {
return LocalDate.parse(date, DateTimeFormatter.ofPattern(pattern)); }
public static String toString(LocalDate date, String pattern) {
return date.format(DateTimeFormatter.ofPattern(pattern));
}
// 计算偏移日期
public static LocalDate getOffsetLocalDate(LocalDate targetDate, ChronoUnit unit, long number) {
return targetDate.plus(number, unit);
} // 获取周一
public static LocalDate getFirstDayOfWeek(LocalDate localDate) {
return localDate.with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY));
} // 获取周日
public static LocalDate getLastDayOfWeek(LocalDate localDate) {
return localDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
} // 获取月初
public static LocalDate getFirstDayOfMonth(LocalDate localDate) {
return localDate.with(TemporalAdjusters.firstDayOfMonth());
} // 获取月末
public static LocalDate getLastDayOfMonth(LocalDate localDate) {
return localDate.with(TemporalAdjusters.lastDayOfMonth());
} // 获取季初
public static LocalDate getFirstDayOfQuarter(LocalDate localDate) {
int month = localDate.getMonthValue();
if (month >= 1 && month <= 3) {
return LocalDate.of(localDate.getYear(), 1, 1);
} else if (month >= 4 && month <= 6) {
return LocalDate.of(localDate.getYear(), 4, 1);
} else if (month >= 7 && month <= 9) {
return LocalDate.of(localDate.getYear(), 7, 1);
} else {
return LocalDate.of(localDate.getYear(), 10, 1);
} } // 获取季末
public static LocalDate getLastDayOfQuarter(LocalDate localDate) {
int month = localDate.getMonthValue();
if (month >= 1 && month <= 3) {
return LocalDate.of(localDate.getYear(), 3, 31);
} else if (month >= 4 && month <= 6) {
return LocalDate.of(localDate.getYear(), 6, 30);
} else if (month >= 7 && month <= 9) {
return LocalDate.of(localDate.getYear(), 9, 30);
} else {
return LocalDate.of(localDate.getYear(), 12, 31);
}
} // 获取半年初
public static LocalDate getFirstDayOfHalfYear(LocalDate localDate) {
int month = localDate.getMonthValue();
if (month >= 1 && month <= 6) {
return LocalDate.of(localDate.getYear(), 1, 1);
} else {
return LocalDate.of(localDate.getYear(), 7, 1);
} } // 获取半年末
public static LocalDate getLastDayOfHalfYear(LocalDate localDate) {
int month = localDate.getMonthValue();
if (month >= 1 && month <= 6) {
return LocalDate.of(localDate.getYear(), 6, 30);
} else {
return LocalDate.of(localDate.getYear(), 12, 31);
}
} // 获取年初
public static LocalDate getFirstDayOfYear(LocalDate localDate) {
return localDate.with(TemporalAdjusters.firstDayOfYear());
} // 获取年末
public static LocalDate getLastDayOfYear(LocalDate localDate) {
return localDate.with(TemporalAdjusters.lastDayOfYear());
} // 计算两个日期相差天数
public static long getIntervalDays(LocalDate localDate1, LocalDate localDate2) {
return Math.abs(localDate1.toEpochDay() - localDate2.toEpochDay());
}

  

最新文章

  1. android FrameLayout详解
  2. bzoj 1079 着色方案
  3. C#开发微信公众平台-就这么简单(附Demo)(转)
  4. Qt5 和 Qt4 的一些改动和不同
  5. oracle 索引失效原因
  6. ORB:新一代 Linux 应用
  7. 一个不错的log4j.properties例子
  8. tomcat 支持https
  9. TDK伪原创? 对matatags的研究总结
  10. 201521123115《Java程序设计》第7周学习总结
  11. 微信支付之h5方式(非微信内置浏览器中支付)
  12. 06-从零玩转JavaWeb-数组在内存当中的存放形式
  13. 转载&amp;修改:赶集mysql军规
  14. 9. Web browser-related (网页浏览器相关 4个)
  15. C++11模版元编程
  16. JAVA-部署-摘
  17. Echart示例
  18. 几个免费IP地址查询API接口
  19. CentOS7防火墙firewalld使用
  20. 【原】Coursera—Andrew Ng机器学习—Week 5 习题—Neural Networks learning

热门文章

  1. ABP的新旧版本
  2. 如何理解c和c++的复杂类型声明
  3. msf generate exec payload
  4. vue入门例子
  5. elementui表格表头合并
  6. compareTo冒泡比较时间字符串
  7. 这 17 个 JVM 参数,高级 Java 必须掌握!
  8. IDEA如何import一个新的项目
  9. ant的安装和使用
  10. git 的版本控制