/**
*
* @note
* @author zhouyy <br>
* Apr 14, 2017 5:21:12 PM
* @version
*/
package com.bytter.util; import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAdjusters;
import java.util.Date; /**
*
* @note
* @author zhouyy <br>
* Apr 14, 2017 5:21:12 PM
* @version
*/
public class NewDate { /**
* 获取当前日期 格式 LocalDate
*
* @return
*/
public static LocalDate getLocalDateNow() {
return LocalDate.now();
} /**
* LocalDate 转 String
*
* @param date
* @return
*/
public static String getLocalDateStr(LocalDate date, String pattern) {
return date.format(DateTimeFormatter.ofPattern(pattern));
} /**
* 取得日期所在月的最后一天 LocalDate
*
* @param date
* @return String
*/
public static String getLastMonthDay(LocalDate date) {
return date.with(TemporalAdjusters.lastDayOfMonth()).toString();
} /**
* 把字符串转成 LocalDate <br>
* strDate 格式就是 aMask
*
* @param aMask
* @param strDate
* @return
*/
public static LocalDate getLocalDate(String aMask, String strDate) {
return LocalDate.parse(strDate, DateTimeFormatter.ofPattern(aMask));
} /**
* java.sql.Date 转 LocaDate<br>
* jdk1.8
*
* @param date
* @return
*/
public static LocalDate sqlDateTolocalDate(java.sql.Date date) {
return date.toLocalDate();
} /**
* java.util.Date 转 LocaDate
*
* @param date
* @return
*/
public static LocalDate DateTolocalDate(Date date) {
return sqlDateTolocalDate(new java.sql.Date(date.getTime()));
} /**
* LocalDate 转 java.util.Date
*
* @param date
* @return
*/
public static Date localDateToDate(LocalDate date) {
try {
return new SimpleDateFormat("yyyy-MM-dd").parse(date.toString());
} catch (ParseException e) {
System.out.println("LocalDate类型 日期转 Date 报错");
e.printStackTrace();
}
return null;
} /**
* LocalDate 转 java.sql.Date
*
* @param date
* @return
*/
public static java.sql.Date localDateToSqlDate(LocalDate date) {
return new java.sql.Date(localDateToDate(date).getTime());
} /**
* 两日期间隔天数
*
* @param date
* @param compareDate
* @return
*/
public static int getSubDayOfDate(LocalDate date, LocalDate compareDate) {
return (int) (date.toEpochDay() - compareDate.toEpochDay());
} /**
* date 加/减 天 对应的日期
*
* @param date
* @param day
* @return
*/
public static LocalDate getBeforeAfterDate(LocalDate date, int day) {
return date.plusDays(day);
} /**
* date 加/减月 对应的日期
*
* @param date
* @param day
* @return
*/
public static LocalDate getBeforeAfterMonth(LocalDate date, int month) {
return date.plusMonths(month);
} /**
* date 加/减年 对应的日期
*
* @param date
* @param day
* @return
*/
public static LocalDate getBeforeAfterYear(LocalDate date, int year) {
return date.plusYears(year);
} /**
* LocalDateTime 类型转 string
*
* @param dateTime
* @return
*/
public static String getLocalDateTime(LocalDateTime dateTime, String pattern) {
return dateTime.format(DateTimeFormatter.ofPattern(pattern));
} }

最新文章

  1. 从匿名方法到 Lambda 表达式的推演过程
  2. G2 2.0 更灵活、更强大、更完备的可视化引擎!
  3. css-display:none和visibility:hidden的不同
  4. javascript类型与类型检测
  5. linux sed 添加 删除 一行
  6. clang LLVM 介绍和安装(Ubuntu10 64位)
  7. [IPA]IOS In App Purchase(内购)验证
  8. Task多线程
  9. ssh-keygen+ssh-copy-id 在linux下实现ssh无密码登录访问(转)
  10. ABySS 拼接工具
  11. linux服务之smtp
  12. php代理请求
  13. [C++程序设计]用数组名作函数参数
  14. C注意,使用的语言字符串
  15. 【成长之路】【python】python基础2
  16. NIO之FileChannel类的理解和使用
  17. 【我们一起写框架】MVVM的WPF框架(二)—绑定
  18. nginx 详细配置
  19. angular笔记_1
  20. leetcode94

热门文章

  1. @OneToMany 一对多 通过表之间的链接
  2. hibernate-HQL连接查询 转载sincoolvip
  3. 条件运算符在GUN C中的特殊用法.
  4. Property &#39;showModal&#39; does no t exist on type &#39;JQuery&lt;HTMLElement&gt;&#39;
  5. 62. Unique Paths (JAVA)
  6. Redis info笔记
  7. ssh远程登录故障解决方案
  8. 独家!三代Ryzen国行价格来了:12核3999
  9. mysql orderby 问题
  10. 【洛谷P2602】数字计数