1.4.1 升级所有依赖,增加DateTimeUtil方法

This commit is contained in:
yexuejc 2021-01-31 13:12:13 +08:00
parent 9d160bdede
commit 9d7d7331c3
5 changed files with 243 additions and 178 deletions

134
README.md
View File

@ -1,67 +1,67 @@
yexuejc-base 基于jdk8常用工具包 yexuejc-base 基于jdk8常用工具包
---------------------- ----------------------
源码地址:<br> 源码地址:<br>
github:https://github.com/yexuejc/yexuejc-base github:https://github.com/yexuejc/yexuejc-base
gitee:https://gitee.com/jzsw-it/yexuejc-base gitee:https://gitee.com/jzsw-it/yexuejc-base
### 说明 ### 说明
>1. 支持环境java8 >1. 支持环境java8
>2. 该工具包基于springboot提取按理说适用于所有java工程 >2. 该工具包基于springboot提取按理说适用于所有java工程
>3. 其中依赖jjwt、validation-api排除请使用 >3. 其中依赖jjwt、validation-api排除请使用
> ``` > ```
> <exclusions> > <exclusions>
> <exclusion> > <exclusion>
> <artifactId>xxx</artifactId> > <artifactId>xxx</artifactId>
> <groupId>xxxx</groupId> > <groupId>xxxx</groupId>
> </exclusion> > </exclusion>
> </exclusions> > </exclusions>
> ``` > ```
> >
>4. `1.1.9` 升级JWT为单例类 >4. `1.1.9` 升级JWT为单例类
>5. `1.2.3` 修复RSA加密(签名)Base64Url 问题如需使用RSA请使用1.2.3+ >5. `1.2.3` 修复RSA加密(签名)Base64Url 问题如需使用RSA请使用1.2.3+
>##### 6. 从`1.3.0`开始,版本维护转由`成都极致思维网络科技有限公司`向maven中央仓库发布版本同时变更组织`groupId``top.yexuejc`。使用者请尽快升级到`1.3.0`以上1.3.0代码向下兼容) >##### 6. 从`1.3.0`开始,变更组织`groupId``top.yexuejc`。使用者请尽快升级到`1.3.0`以上1.3.0代码向下兼容)
### 使用 ### 使用
>yexuejc.base.version=1.3.0 >yexuejc.base.version=1.4.1
pom.xml pom.xml
``` ```
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>top.yexuejc</groupId> <groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId> <artifactId>yexuejc-base</artifactId>
<version>${yexuejc.base.version}</version> <version>${yexuejc.base.version}</version>
</dependency> </dependency>
</dependencies> </dependencies>
``` ```
#### 附1.3.0之前的使用方式 #### 附1.3.0之前的使用方式
pom.xml pom.xml
``` ```
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>com.yexuejc.base</groupId> <groupId>com.yexuejc.base</groupId>
<artifactId>yexuejc-base</artifactId> <artifactId>yexuejc-base</artifactId>
<version>1.3.0以下</version> <version>1.3.0以下</version>
</dependency> </dependency>
</dependencies> </dependencies>
<repositories> <repositories>
<repository> <repository>
<id>yexuejc-nexus-public</id> <id>yexuejc-nexus-public</id>
<name>yexuejc-nexus-public</name> <name>yexuejc-nexus-public</name>
<url>https://nexus.yexuejc.club/repository/maven-public/</url> <url>https://nexus.yexuejc.club/repository/maven-public/</url>
</repository> </repository>
</repositories> </repositories>
``` ```
### 工具文档 ### 工具文档
[Wiki](WIKI.md) [Wiki](WIKI.md)
### 更新日志 ### 更新日志
[更新记录](UPDATE.md) [更新记录](UPDATE.md)
#### 项目发展 #### 项目发展
本工程项目由maxf基于日常使用从[yexuejc-springboot](https://github.com/yexuejc/yexuejc-springboot.git)_准备移交版本控制_中抽离开源独立发展后续增加许多常用工具包。 本工程项目由maxf基于日常使用从[yexuejc-springboot](https://github.com/yexuejc/yexuejc-springboot.git)_准备移交版本控制_中抽离开源独立发展后续增加许多常用工具包。
使用者逐渐增多后考虑可靠性和稳定性原则,移交版本控制给`成都极致思维网络科技有限公司`管理maven包直接发布到中央仓库。 使用者逐渐增多后考虑可靠性和稳定性原则,移交版本控制给`成都极致思维网络科技有限公司`管理maven包直接发布到中央仓库。
开源工程项目仍然保持继续维护和欢迎更多愿意贡献的小伙伴参与。 开源工程项目仍然保持继续维护和欢迎更多愿意贡献的小伙伴参与。

View File

@ -1,6 +1,19 @@
yexuejc-base 更新记录 yexuejc-base 更新记录
------------------ ------------------
#### version 1.4.1
**time2021-1-31 12:59:24** <br/>
**branch** master <br/>
**update** <br/>
>1. 升级所有依赖
>1. 增加DateTimeUtil类的功能
#
#### version 1.4.0
**time2020-04-13 20:49:32** <br/>
**branch** master <br/>
**update** <br/>
>1. 优化Execl 和 Jwt 工具
#
#### version 1.3.9 #### version 1.3.9
**time2019-1-11 16:50:51** <br/> **time2019-1-11 16:50:51** <br/>
**branch** master <br/> **branch** master <br/>

123
pom.xml
View File

@ -6,7 +6,7 @@
<groupId>top.yexuejc</groupId> <groupId>top.yexuejc</groupId>
<artifactId>yexuejc-base</artifactId> <artifactId>yexuejc-base</artifactId>
<version>1.4.0</version> <version>1.4.1</version>
<name>${project.artifactId}</name> <name>${project.artifactId}</name>
<url>https://github.com/yexuejc/yexuejc-base</url> <url>https://github.com/yexuejc/yexuejc-base</url>
@ -39,19 +39,19 @@
</scm> </scm>
<properties> <properties>
<repos.yexuejc.url>https://nexus.yexuejc.club/repository/</repos.yexuejc.url> <repos.yexuejc.url>https://nexus.yexuejc.top/repository/</repos.yexuejc.url>
<repos.mcworle.url>https://nexus.mcworle.com/repository/</repos.mcworle.url> <repos.hm.url>https://nexus.hm3981.com/repository/</repos.hm.url>
<repos.aliyun.url>http://maven.aliyun.com/nexus/content/groups/public</repos.aliyun.url> <repos.aliyun.url>http://maven.aliyun.com/nexus/content/groups/public</repos.aliyun.url>
<repos.jitpack.url>https://jitpack.io</repos.jitpack.url> <repos.jitpack.url>https://jitpack.io</repos.jitpack.url>
<jjwt.version>0.7.0</jjwt.version> <jjwt.version>0.9.1</jjwt.version>
<maven.compiler.verbose>true</maven.compiler.verbose> <maven.compiler.verbose>true</maven.compiler.verbose>
<java.version>1.8</java.version> <java.version>1.8</java.version>
<validation-api.version>1.1.0.Final</validation-api.version> <validation-api.version>3.0.0</validation-api.version>
<commons-codec.version>1.10</commons-codec.version> <commons-codec.version>1.15</commons-codec.version>
<commons-io.version>2.6</commons-io.version> <commons-io.version>2.8.0</commons-io.version>
<bcprov-jdk15on.version>1.60</bcprov-jdk15on.version> <bcprov-jdk15on.version>1.68</bcprov-jdk15on.version>
<guava.version>20.0</guava.version> <guava.version>30.1-jre</guava.version>
<apache-poi.version>3.13</apache-poi.version> <apache-poi.version>5.0.0</apache-poi.version>
<!-- 文件拷贝时的编码 --> <!-- 文件拷贝时的编码 -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
@ -67,9 +67,15 @@
<version>${jjwt.version}</version> <version>${jjwt.version}</version>
</dependency> </dependency>
<!-- 数据校验框架 --> <!-- 数据校验框架 -->
<!-- <dependency>-->
<!-- <groupId>javax.validation</groupId>-->
<!-- <artifactId>validation-api</artifactId>-->
<!-- <version>${validation-api.version}</version>-->
<!-- </dependency>-->
<!-- https://mvnrepository.com/artifact/jakarta.validation/jakarta.validation-api -->
<dependency> <dependency>
<groupId>javax.validation</groupId> <groupId>jakarta.validation</groupId>
<artifactId>validation-api</artifactId> <artifactId>jakarta.validation-api</artifactId>
<version>${validation-api.version}</version> <version>${validation-api.version}</version>
</dependency> </dependency>
<!--base64使用到的依赖--> <!--base64使用到的依赖-->
@ -118,6 +124,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId> <artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration> <configuration>
<encoding>UTF-8</encoding> <encoding>UTF-8</encoding>
<source>8</source> <source>8</source>
@ -128,7 +135,7 @@
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId> <artifactId>maven-source-plugin</artifactId>
<version>3.0.1</version> <version>3.2.1</version>
<executions> <executions>
<execution> <execution>
<id>attach-sources</id> <id>attach-sources</id>
@ -139,48 +146,50 @@
</executions> </executions>
</plugin> </plugin>
<!-- 使用spring boot的maven插件进行打包 --> <!-- 使用spring boot的maven插件进行打包 -->
<plugin> <!-- <plugin>-->
<groupId>org.springframework.boot</groupId> <!-- <groupId>org.springframework.boot</groupId>-->
<artifactId>spring-boot-maven-plugin</artifactId> <!-- <artifactId>spring-boot-maven-plugin</artifactId>-->
<executions> <!-- <version>2.4.2</version>-->
<execution> <!-- <executions>-->
<goals> <!-- <execution>-->
<goal>build-info</goal> <!-- <goals>-->
</goals> <!-- <goal>build-info</goal>-->
</execution> <!-- </goals>-->
</executions> <!-- </execution>-->
<configuration> <!-- </executions>-->
<!-- 是否打出可执行的jar包(仅支持Linux格式) --> <!-- <configuration>-->
<executable>true</executable> <!-- &lt;!&ndash; 是否打出可执行的jar包(仅支持Linux格式) &ndash;&gt;-->
</configuration> <!-- <executable>true</executable>-->
</plugin> <!-- </configuration>-->
<!-- </plugin>-->
<!-- Javadoc --> <!-- Javadoc -->
<!--<plugin>--> <!-- <plugin>-->
<!--<groupId>org.apache.maven.plugins</groupId>--> <!-- <groupId>org.apache.maven.plugins</groupId>-->
<!--<artifactId>maven-javadoc-plugin</artifactId>--> <!-- <artifactId>maven-javadoc-plugin</artifactId>-->
<!--<executions>--> <!-- <executions>-->
<!--<execution>--> <!-- <execution>-->
<!--<phase>package</phase>--> <!-- <phase>package</phase>-->
<!--<goals>--> <!-- <goals>-->
<!--<goal>jar</goal>--> <!-- <goal>jar</goal>-->
<!--</goals>--> <!-- </goals>-->
<!--</execution>--> <!-- </execution>-->
<!--</executions>--> <!-- </executions>-->
<!--</plugin>--> <!-- </plugin>-->
<!-- GPG --> <!-- GPG -->
<!--<plugin> &lt;!&ndash; 进行延签 &ndash;&gt;--> <!-- 进行延签 -->
<!--<groupId>org.apache.maven.plugins</groupId>--> <!-- <plugin> -->
<!--<artifactId>maven-gpg-plugin</artifactId>--> <!-- <groupId>org.apache.maven.plugins</groupId>-->
<!--<version>1.6</version>--> <!-- <artifactId>maven-gpg-plugin</artifactId>-->
<!--<executions>--> <!-- <version>1.6</version>-->
<!--<execution>--> <!-- <executions>-->
<!--<phase>verify</phase>--> <!-- <execution>-->
<!--<goals>--> <!-- <phase>verify</phase>-->
<!--<goal>sign</goal>--> <!-- <goals>-->
<!--</goals>--> <!-- <goal>sign</goal>-->
<!--</execution>--> <!-- </goals>-->
<!--</executions>--> <!-- </execution>-->
<!--</plugin>--> <!-- </executions>-->
<!-- </plugin>-->
</plugins> </plugins>
</build> </build>
<repositories> <repositories>
@ -226,16 +235,16 @@
<url>${repos.yexuejc.url}maven-snapshots/</url> <url>${repos.yexuejc.url}maven-snapshots/</url>
</snapshotRepository> </snapshotRepository>
<!--
<!-- <repository> <repository>
<id>releases</id> <id>releases</id>
<name>nexus-release</name> <name>nexus-release</name>
<url>${repos.mcworle.url}maven-releases/</url> <url>${repos.hm.url}maven-releases/</url>
</repository> </repository>
<snapshotRepository> <snapshotRepository>
<id>snapshots</id> <id>snapshots</id>
<name>nexus-snapshots</name> <name>nexus-snapshots</name>
<url>${repos.mcworle.url}maven-snapshots/</url> <url>${repos.hm.url}maven-snapshots/</url>
</snapshotRepository>--> </snapshotRepository>-->
</distributionManagement> </distributionManagement>

View File

@ -148,6 +148,55 @@ public class DateTimeUtil {
return date; return date;
} }
/**
* LocalDate Date
*
* @param localDate
* @return
*/
public static Date parseDate(LocalDate localDate) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);
}
/**
* LocalDateTime Date
*
* @param localDateTime
* @return
*/
public static Date parseDate(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* LocalTime Date
*
* @param localTime 时间
* @return 当前日期的指定时间
*/
public static Date parseDate(LocalTime localTime) {
LocalDate localDate = LocalDate.now();
return parseDate(localDate, localTime);
}
/**
* LocalDate + LocalTime Date
*
* @param localDate 日期
* @param localTime 时间
* @return 指定日期的指定时间
*/
public static Date parseDate(LocalDate localDate, LocalTime localTime) {
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime);
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return Date.from(instant);
}
/** /**
* Date ZonedDateTime * Date ZonedDateTime
* *
@ -172,30 +221,6 @@ public class DateTimeUtil {
return instant.atZone(zoneId).toLocalDateTime(); return instant.atZone(zoneId).toLocalDateTime();
} }
/**
* LocalDateTime Date
*
* @param localDateTime
* @return
*/
public static Date parseLocalDateTime(LocalDateTime localDateTime) {
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime zdt = localDateTime.atZone(zoneId);
return Date.from(zdt.toInstant());
}
/**
* LocalDate Date
*
* @param localDate
* @return
*/
public static Date parseData(LocalDate localDate) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDate.atStartOfDay().atZone(zone).toInstant();
return Date.from(instant);
}
/** /**
* Date LocalDate * Date LocalDate
* *
@ -204,9 +229,8 @@ public class DateTimeUtil {
*/ */
public static LocalDate parseLocalDate(Date date) { public static LocalDate parseLocalDate(Date date) {
Instant instant = date.toInstant(); Instant instant = date.toInstant();
ZoneId zone = ZoneId.systemDefault(); ZoneId zoneId = ZoneId.systemDefault();
LocalDateTime localDateTime = LocalDateTime.ofInstant(instant, zone); return instant.atZone(zoneId).toLocalDate();
return localDateTime.toLocalDate();
} }
/** /**
@ -223,30 +247,40 @@ public class DateTimeUtil {
} }
/** /**
* Date LocalTime * Long LocalDateTime
* *
* @param localTime * @param timestamp 13位毫秒
* @return 当前日期的指定时间 * @return
*/ */
public static Date parseDate(LocalTime localTime) { public static LocalDateTime parseLocalDateTime13(long timestamp) {
LocalDate localDate = LocalDate.now(); Instant instant = Instant.ofEpochMilli(timestamp);
return parseDate(localDate, localTime); ZoneId zone = ZoneId.systemDefault();
return LocalDateTime.ofInstant(instant, zone);
} }
/** /**
* Date LocalTime * Long LocalDateTime
* *
* @param localDate * @param timestamp 10位
* @param localTime * @return
* @return 指定日期的指定时间
*/ */
public static Date parseDate(LocalDate localDate, LocalTime localTime) { public static LocalDateTime parseLocalDateTime10(long timestamp) {
LocalDateTime localDateTime = LocalDateTime.of(localDate, localTime); Instant instant = Instant.ofEpochMilli(timestamp * 1000);
ZoneId zone = ZoneId.systemDefault(); ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant(); return LocalDateTime.ofInstant(instant, zone);
return Date.from(instant);
} }
/**
* LocalDateTime Long
*
* @param localDateTime
* @return 13位毫秒
*/
public static long parseLong(LocalDateTime localDateTime) {
ZoneId zone = ZoneId.systemDefault();
Instant instant = localDateTime.atZone(zone).toInstant();
return instant.toEpochMilli();
}
/** /**
* 格式化时间 <br/> * 格式化时间 <br/>
* 格式 yyyy-MM-dd HH:mm:ss * 格式 yyyy-MM-dd HH:mm:ss
@ -255,7 +289,7 @@ public class DateTimeUtil {
* @return * @return
*/ */
public static String format(LocalDateTime dateTime) { public static String format(LocalDateTime dateTime) {
return format(dateTime, ""); return format(dateTime, null);
} }
/** /**
@ -273,22 +307,23 @@ public class DateTimeUtil {
return df.format(dateTime); return df.format(dateTime);
} }
/** public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(df.format(zonedDateTime2Date(ZonedDateTime.now())));
System.out.println(df2.format(date2ZonedDateTime(new Date())));
System.out.println(getWeek4First()); /** public static void main(String[] args) {
System.out.println(format(getWeek4First(LocalDate.parse("2018-02-10")).atTime(LocalTime.MIN))); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(format(getWeek4Last(LocalDate.parse("2018-02-10")).atTime(LocalTime.MAX))); System.out.println(df.format(zonedDateTime2Date(ZonedDateTime.now())));
System.out.println(df2.format(date2ZonedDateTime(new Date())));
System.out.println(format(getMonth4First().atTime(LocalTime.MIN))); System.out.println(getWeek4First());
System.out.println(format(getMonth4Last().atTime(LocalTime.MAX))); System.out.println(format(getWeek4First(LocalDate.parse("2018-02-10")).atTime(LocalTime.MIN)));
System.out.println(format(getWeek4Last(LocalDate.parse("2018-02-10")).atTime(LocalTime.MAX)));
System.out.println(format(getYear4First().atTime(LocalTime.MIN))); System.out.println(format(getMonth4First().atTime(LocalTime.MIN)));
System.out.println(format(getYear4Last().atTime(LocalTime.MAX))); System.out.println(format(getMonth4Last().atTime(LocalTime.MAX)));
}*/ System.out.println(format(getYear4First().atTime(LocalTime.MIN)));
System.out.println(format(getYear4Last().atTime(LocalTime.MAX)));
}*/
} }

View File

@ -2,18 +2,26 @@ package com.yexuejc.base.util;
import java.lang.annotation.*; import java.lang.annotation.*;
/**
* json转换时的格式指定
*
* @author: yexuejc
* @date: 2021-01-31 12:48:29
*/
@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD}) @Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
public @interface ToUeProperty { public @interface ToUeProperty {
/** /**
* 字段名默认该字段转下划线 * 字段名默认该字段转下划线
*
* @return * @return
*/ */
String value() default ""; String value() default "";
/** /**
* 是否忽略该字段默认false * 是否忽略该字段默认false
*
* @return * @return
*/ */
boolean ignore() default false; boolean ignore() default false;