Compare commits
11
Commits
dev
..
f354c232fe
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f354c232fe | ||
|
|
c75b1b895c | ||
|
|
06abba8765 | ||
|
|
4e8351fee9 | ||
|
|
97809cd321 | ||
|
|
b9d47baa1a | ||
|
|
a4bcc3bf57 | ||
|
|
6361c70f37 | ||
|
|
e793a260be | ||
|
|
2020cb9111 | ||
|
|
b686679014 |
@@ -6,7 +6,7 @@
|
|||||||
|
|
||||||
<groupId>com.imyeyu.utils</groupId>
|
<groupId>com.imyeyu.utils</groupId>
|
||||||
<artifactId>timi-utils</artifactId>
|
<artifactId>timi-utils</artifactId>
|
||||||
<version>0.0.13</version>
|
<version>0.0.12</version>
|
||||||
|
|
||||||
<properties>
|
<properties>
|
||||||
<maven.test.skip>true</maven.test.skip>
|
<maven.test.skip>true</maven.test.skip>
|
||||||
@@ -91,7 +91,7 @@
|
|||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.imyeyu.java</groupId>
|
<groupId>com.imyeyu.java</groupId>
|
||||||
<artifactId>timi-java</artifactId>
|
<artifactId>timi-java</artifactId>
|
||||||
<version>0.0.7</version>
|
<version>0.0.5</version>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>de.mkammerer</groupId>
|
<groupId>de.mkammerer</groupId>
|
||||||
|
|||||||
@@ -435,8 +435,4 @@ public class Text {
|
|||||||
public static String bizClassName(Class<?> clazz) {
|
public static String bizClassName(Class<?> clazz) {
|
||||||
return underscoreClassName(clazz).toUpperCase();
|
return underscoreClassName(clazz).toUpperCase();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String normalize(String text) {
|
|
||||||
return TimiJava.defaultIfEmpty(text, null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package com.imyeyu.utils;
|
package com.imyeyu.utils;
|
||||||
|
|
||||||
import com.imyeyu.java.TimiJava;
|
import com.imyeyu.java.TimiJava;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.time.LocalDate;
|
import java.time.LocalDate;
|
||||||
import java.time.LocalDateTime;
|
import java.time.LocalDateTime;
|
||||||
import java.time.ZoneId;
|
import java.time.ZoneId;
|
||||||
|
import java.time.temporal.ChronoUnit;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
@@ -75,9 +77,6 @@ public class Time {
|
|||||||
/** 格式化 yyyy-MM-dd'T'HH:mm:ss */
|
/** 格式化 yyyy-MM-dd'T'HH:mm:ss */
|
||||||
public static final SimpleDateFormat dateTimeT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
public static final SimpleDateFormat dateTimeT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
|
||||||
|
|
||||||
/** 格式化 yyyy-MM-dd HH:mm:ss */
|
|
||||||
public static final SimpleDateFormat serialize = new SimpleDateFormat("yyyyMMddHHmmss");
|
|
||||||
|
|
||||||
// ---------- 长整型时间戳 ----------
|
// ---------- 长整型时间戳 ----------
|
||||||
|
|
||||||
/** 1 秒时间戳 */
|
/** 1 秒时间戳 */
|
||||||
@@ -106,6 +105,31 @@ public class Time {
|
|||||||
/** 1 天时间戳(整型) */
|
/** 1 天时间戳(整型) */
|
||||||
public static final int DI = HI * 24;
|
public static final int DI = HI * 24;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 计算两个时间戳精确的日期时间差
|
||||||
|
*
|
||||||
|
* @param begin 开始时间戳
|
||||||
|
* @param end 结束时间戳
|
||||||
|
* @return 时差
|
||||||
|
*/
|
||||||
|
public static Between between(long begin, long end) {
|
||||||
|
if (end < begin) {
|
||||||
|
throw new IllegalArgumentException("end time must greater than begin time:" + end + " < " + begin);
|
||||||
|
}
|
||||||
|
LocalDateTime ldtBegin = toLocalDateTime(begin);
|
||||||
|
LocalDateTime ldtEnd = toLocalDateTime(end);
|
||||||
|
|
||||||
|
Between between = new Between();
|
||||||
|
between.year = (int) ChronoUnit.YEARS.between(ldtBegin, ldtEnd);
|
||||||
|
between.month = (int) ChronoUnit.MONTHS.between(ldtBegin, ldtEnd) % 12;
|
||||||
|
between.day = (int) ChronoUnit.DAYS.between(ldtBegin.plusMonths(between.year * 12L + between.month), ldtEnd);
|
||||||
|
between.hour = (int) (ChronoUnit.HOURS.between(ldtBegin, ldtEnd) - ChronoUnit.DAYS.between(ldtBegin, ldtEnd) * 24);
|
||||||
|
between.minute = (int) ChronoUnit.MINUTES.between(ldtBegin, ldtEnd) % 60;
|
||||||
|
between.second = (int) ChronoUnit.SECONDS.between(ldtBegin, ldtEnd) % 60;
|
||||||
|
between.millis = (int) ((end - begin) % 1000);
|
||||||
|
return between;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取此刻毫秒
|
* 获取此刻毫秒
|
||||||
*
|
*
|
||||||
@@ -130,11 +154,7 @@ public class Time {
|
|||||||
* @return 昨天零时时间戳
|
* @return 昨天零时时间戳
|
||||||
*/
|
*/
|
||||||
public static long yesterday() {
|
public static long yesterday() {
|
||||||
return yesterday(now());
|
return today() - D;
|
||||||
}
|
|
||||||
|
|
||||||
public static long yesterday(long time) {
|
|
||||||
return today(time) - D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -143,11 +163,9 @@ public class Time {
|
|||||||
* @return 今天零时时间戳
|
* @return 今天零时时间戳
|
||||||
*/
|
*/
|
||||||
public static long today() {
|
public static long today() {
|
||||||
return today(now());
|
long now = now();
|
||||||
}
|
final long H8 = H * 8;
|
||||||
|
return ((now + H8 - (now + H8) % (H * 24)) - H8);
|
||||||
public static long today(long time) {
|
|
||||||
return Instant.ofEpochMilli(time).atZone(ZoneId.systemDefault()).toLocalDate().atStartOfDay(ZoneId.systemDefault()).toInstant().toEpochMilli();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -156,11 +174,7 @@ public class Time {
|
|||||||
* @return 明天零时时间戳
|
* @return 明天零时时间戳
|
||||||
*/
|
*/
|
||||||
public static long tomorrow() {
|
public static long tomorrow() {
|
||||||
return tomorrow(now());
|
return today() + D;
|
||||||
}
|
|
||||||
|
|
||||||
public static long tomorrow(long time) {
|
|
||||||
return today(time) + D;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -366,4 +380,35 @@ public class Time {
|
|||||||
return String.format("%d:%02d:%02d.%03d", h, s / 60 - h * 60, s % 60, millis % 1000);
|
return String.format("%d:%02d:%02d.%03d", h, s / 60 - h * 60, s % 60, millis % 1000);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 时差
|
||||||
|
*
|
||||||
|
* @author 夜雨
|
||||||
|
* @version 2022-10-12 14:46
|
||||||
|
*/
|
||||||
|
@Getter
|
||||||
|
public static class Between {
|
||||||
|
|
||||||
|
/** 年 */
|
||||||
|
int year;
|
||||||
|
|
||||||
|
/** 月 */
|
||||||
|
int month;
|
||||||
|
|
||||||
|
/** 天 */
|
||||||
|
int day;
|
||||||
|
|
||||||
|
/** 小时 */
|
||||||
|
int hour;
|
||||||
|
|
||||||
|
/** 分钟 */
|
||||||
|
int minute;
|
||||||
|
|
||||||
|
/** 秒 */
|
||||||
|
int second;
|
||||||
|
|
||||||
|
/** 毫秒 */
|
||||||
|
int millis;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user