增加Times
This commit is contained in:
@@ -2014,7 +2014,7 @@ public final class Application {
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Utility.midnight(); //先初始化一下Utility
|
||||
Times.midnight(); //先初始化一下Utility
|
||||
Thread.currentThread().setName("Redkale-Application-Main-Thread");
|
||||
//运行主程序
|
||||
{
|
||||
|
||||
@@ -180,14 +180,14 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
}
|
||||
if (logstream == null) {
|
||||
logindex.incrementAndGet();
|
||||
logfile = new File(patternDateFormat == null ? pattern : Utility.formatTime(patternDateFormat, -1, System.currentTimeMillis()));
|
||||
logfile = new File(patternDateFormat == null ? pattern : Times.formatTime(patternDateFormat, -1, System.currentTimeMillis()));
|
||||
logfile.getParentFile().mkdirs();
|
||||
logLength.set(logfile.length());
|
||||
logstream = new FileOutputStream(logfile, append);
|
||||
}
|
||||
if (unusual != null && logunusualstream == null) {
|
||||
logunusualindex.incrementAndGet();
|
||||
logunusualfile = new File(unusualDateFormat == null ? unusual : Utility.formatTime(unusualDateFormat, -1, System.currentTimeMillis()));
|
||||
logunusualfile = new File(unusualDateFormat == null ? unusual : Times.formatTime(unusualDateFormat, -1, System.currentTimeMillis()));
|
||||
logunusualfile.getParentFile().mkdirs();
|
||||
logUnusualLength.set(logunusualfile.length());
|
||||
logunusualstream = new FileOutputStream(logunusualfile, append);
|
||||
@@ -234,7 +234,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
}
|
||||
if (this.pattern != null && this.pattern.contains("%")) { //需要时间格式化
|
||||
this.patternDateFormat = this.pattern;
|
||||
Utility.formatTime(this.patternDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
Times.formatTime(this.patternDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
}
|
||||
String unusualstr = manager.getProperty(cname + ".unusual");
|
||||
if (unusualstr != null) {
|
||||
@@ -247,7 +247,7 @@ public class LoggingFileHandler extends LoggingBaseHandler {
|
||||
}
|
||||
if (this.unusual != null && this.unusual.contains("%")) { //需要时间格式化
|
||||
this.unusualDateFormat = this.unusual;
|
||||
Utility.formatTime(this.unusualDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
Times.formatTime(this.unusualDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
}
|
||||
String limitstr = manager.getProperty(cname + ".limit");
|
||||
try {
|
||||
|
||||
@@ -163,7 +163,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
this.tag = tagstr.replace("${" + RESNAME_APP_NAME + "}", System.getProperty(RESNAME_APP_NAME, ""));
|
||||
if (this.tag.contains("%")) {
|
||||
this.tagDateFormat = this.tag;
|
||||
Utility.formatTime(this.tagDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
Times.formatTime(this.tagDateFormat, -1, System.currentTimeMillis()); //测试时间格式是否正确
|
||||
}
|
||||
}
|
||||
|
||||
@@ -233,7 +233,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
break;
|
||||
}
|
||||
}
|
||||
String rawTag = tagDateFormat == null ? tag : Utility.formatTime(tagDateFormat, -1, log.getInstant().toEpochMilli());
|
||||
String rawTag = tagDateFormat == null ? tag : Times.formatTime(tagDateFormat, -1, log.getInstant().toEpochMilli());
|
||||
fillLogRecord(log);
|
||||
logqueue.offer(new SearchLogRecord(rawTag, log));
|
||||
}
|
||||
@@ -317,7 +317,7 @@ public class LoggingSearchHandler extends LoggingBaseHandler {
|
||||
this.loggerName = log.getLoggerName();
|
||||
this.methodName = log.getSourceClassName() + " " + log.getSourceMethodName();
|
||||
this.timestamp = log.getInstant().toEpochMilli();
|
||||
this.logid = Utility.format36time(timestamp) + "_" + Utility.uuid();
|
||||
this.logid = Times.format36time(timestamp) + "_" + Utility.uuid();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,7 @@ package org.redkale.source;
|
||||
|
||||
import java.util.function.*;
|
||||
import org.redkale.convert.ConvertColumn;
|
||||
import org.redkale.util.Utility;
|
||||
import org.redkale.util.Times;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -209,12 +209,12 @@ public interface Range<E extends Comparable> extends java.io.Serializable, Predi
|
||||
}
|
||||
|
||||
public static LongRange todayRange() {
|
||||
long min = Utility.midnight();
|
||||
long min = Times.midnight();
|
||||
return new LongRange(min, min + 24 * 60 * 60 * 1000 - 1);
|
||||
}
|
||||
|
||||
public static LongRange yesterdayRange() {
|
||||
long min = Utility.midnight(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
|
||||
long min = Times.midnight(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
|
||||
return new LongRange(min, min + 24 * 60 * 60 * 1000 - 1);
|
||||
}
|
||||
|
||||
|
||||
372
src/main/java/org/redkale/util/Times.java
Normal file
372
src/main/java/org/redkale/util/Times.java
Normal file
@@ -0,0 +1,372 @@
|
||||
/*
|
||||
*
|
||||
*/
|
||||
package org.redkale.util;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.time.LocalDate;
|
||||
import java.time.ZoneId;
|
||||
import java.util.Calendar;
|
||||
import java.util.TimeZone;
|
||||
|
||||
/**
|
||||
* 时间日期工具类
|
||||
*
|
||||
* <p>
|
||||
* 详情见: https://redkale.org
|
||||
*
|
||||
* @author zhangjx
|
||||
* @since 2.8.0
|
||||
*/
|
||||
public class Times {
|
||||
|
||||
private static final int ZONE_RAW_OFFSET = TimeZone.getDefault().getRawOffset();
|
||||
|
||||
static final String FORMAT_SECONDS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"; //yyyy-MM-dd HH:mm:ss
|
||||
|
||||
static final String FORMAT_MILLS = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL"; //yyyy-MM-dd HH:mm:ss.fff
|
||||
|
||||
private Times() {
|
||||
//do nothind
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取格式为yyyy-MM-dd HH:mm:ss的当前时间
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss的时间值
|
||||
*/
|
||||
public static String now() {
|
||||
return String.format(FORMAT_SECONDS, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取格式为yyyy-MM-dd HH:mm:ss.fff的当前时间
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss.fff的时间值
|
||||
*/
|
||||
public static String nowMillis() {
|
||||
return String.format(FORMAT_MILLS, System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 将指定时间格式化为 yyyy-MM-dd HH:mm:ss
|
||||
*
|
||||
* @param time 待格式化的时间
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss的时间值
|
||||
*/
|
||||
public static String formatTime(long time) {
|
||||
return String.format(FORMAT_SECONDS, time);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间值转换为长度为9的36进制值
|
||||
*
|
||||
* @param time 时间值
|
||||
*
|
||||
* @return 36进制时间值
|
||||
*/
|
||||
public static String format36time(long time) {
|
||||
return Long.toString(time, 36);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天凌晨零点的格林时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long midnight() {
|
||||
return midnight(System.currentTimeMillis());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间当天凌晨零点的格林时间
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long midnight(long time) {
|
||||
return (time + ZONE_RAW_OFFSET) / 86400000 * 86400000 - ZONE_RAW_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天20151231格式的int值
|
||||
*
|
||||
* @return 20151231格式的int值
|
||||
*/
|
||||
public static int today() {
|
||||
java.time.LocalDate today = java.time.LocalDate.now();
|
||||
return today.getYear() * 10000
|
||||
+ today.getMonthValue() * 100
|
||||
+ today.getDayOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天151231格式的int值
|
||||
*
|
||||
* @return 151231格式的int值
|
||||
*/
|
||||
public static int todayYYMMDD() {
|
||||
java.time.LocalDate today = java.time.LocalDate.now();
|
||||
return today.getYear() % 100 * 10000
|
||||
+ today.getMonthValue() * 100
|
||||
+ today.getDayOfMonth();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天1512312359格式的int值
|
||||
*
|
||||
* @return 1512312359格式的int值
|
||||
*/
|
||||
public static int todayYYMMDDHHmm() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() % 100 * 100_00_00_00
|
||||
+ today.getMonthValue() * 100_00_00
|
||||
+ today.getDayOfMonth() * 100_00
|
||||
+ today.getHour() * 100
|
||||
+ today.getMinute();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天20151231235959格式的int值
|
||||
*
|
||||
* @return 20151231235959格式的int值
|
||||
*/
|
||||
public static long todayYYYYMMDDHHmmss() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() * 100_00_00_00_00L
|
||||
+ today.getMonthValue() * 100_00_00_00
|
||||
+ today.getDayOfMonth() * 100_00_00
|
||||
+ today.getHour() * 100_00
|
||||
+ today.getMinute() * 100
|
||||
+ today.getSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天151231235959格式的int值
|
||||
*
|
||||
* @return 151231235959格式的int值
|
||||
*/
|
||||
public static long todayYYMMDDHHmmss() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() % 100 * 100_00_00_00_00L
|
||||
+ today.getMonthValue() * 100_00_00_00
|
||||
+ today.getDayOfMonth() * 100_00_00
|
||||
+ today.getHour() * 100_00
|
||||
+ today.getMinute() * 100
|
||||
+ today.getSecond();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取明天20151230格式的int值
|
||||
*
|
||||
* @return 20151230格式的int值
|
||||
*/
|
||||
public static int tomorrow() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
return cal.get(Calendar.YEAR) * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取明天151230格式的int值
|
||||
*
|
||||
* @return 151230格式的int值
|
||||
*/
|
||||
public static int tomorrowYYMMDD() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨天20151230格式的int值
|
||||
*
|
||||
* @return 20151230格式的int值
|
||||
*/
|
||||
public static int yesterday() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
return cal.get(Calendar.YEAR) * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取昨天151230格式的int值
|
||||
*
|
||||
* @return 151230格式的int值
|
||||
*/
|
||||
public static int yesterdayYYMMDD() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间的20160202格式的int值
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static int yyyyMMdd(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间的160202格式的int值
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static int yyMMdd(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100
|
||||
+ cal.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天16020223格式的int值
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 16020223格式的int值
|
||||
*/
|
||||
public static int yyMMDDHHmm(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) % 100 * 100_00_00
|
||||
+ (cal.get(Calendar.MONTH) + 1) * 100_00
|
||||
+ cal.get(Calendar.DAY_OF_MONTH) * 100
|
||||
+ cal.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间点所在星期的周一
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long monday(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.minusDays(ld.getDayOfWeek().getValue() - 1);
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间点所在星期的周日
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long sunday(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.plusDays(7 - ld.getDayOfWeek().getValue());
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间点所在月份的1号
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long monthFirstDay(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate().withDayOfMonth(1);
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取时间点所在月份的最后一天
|
||||
*
|
||||
* @param time 指定时间
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
public static long monthLastDay(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.withDayOfMonth(ld.lengthOfMonth());
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
}
|
||||
|
||||
/**
|
||||
* 将时间格式化, 支持%1$ty 和 %ty两种格式
|
||||
*
|
||||
* @param format 格式
|
||||
* @param size 带%t的个数,值小于0则需要计算
|
||||
* @param time 时间
|
||||
*
|
||||
* @since 2.7.0
|
||||
*
|
||||
* @return 时间格式化
|
||||
*/
|
||||
public static String formatTime(String format, int size, Object time) {
|
||||
if (size < 0) {
|
||||
int c = 0;
|
||||
if (!format.contains("%1$")) {
|
||||
for (char ch : format.toCharArray()) {
|
||||
if (ch == '%') {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
size = c;
|
||||
}
|
||||
if (size <= 1) {
|
||||
return String.format(format, time);
|
||||
}
|
||||
if (size == 2) {
|
||||
return String.format(format, time, time);
|
||||
}
|
||||
if (size == 3) {
|
||||
return String.format(format, time, time, time);
|
||||
}
|
||||
if (size == 4) {
|
||||
return String.format(format, time, time, time, time);
|
||||
}
|
||||
if (size == 5) {
|
||||
return String.format(format, time, time, time, time, time);
|
||||
}
|
||||
if (size == 6) {
|
||||
return String.format(format, time, time, time, time, time, time);
|
||||
}
|
||||
if (size == 7) {
|
||||
return String.format(format, time, time, time, time, time, time, time);
|
||||
}
|
||||
if (size == 8) {
|
||||
return String.format(format, time, time, time, time, time, time, time);
|
||||
}
|
||||
Object[] args = new Object[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
args[i] = time;
|
||||
}
|
||||
return String.format(format, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -39,12 +39,6 @@ import org.redkale.convert.json.JsonConvert;
|
||||
*/
|
||||
public final class Utility {
|
||||
|
||||
private static final int zoneRawOffset = TimeZone.getDefault().getRawOffset();
|
||||
|
||||
static final String format1 = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS"; //yyyy-MM-dd HH:mm:ss
|
||||
|
||||
static final String format2 = "%1$tY-%1$tm-%1$td %1$tH:%1$tM:%1$tS.%1$tL"; //yyyy-MM-dd HH:mm:ss.fff
|
||||
|
||||
private static final char hex[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};
|
||||
|
||||
private static final int cpus = Integer.getInteger("redkale.cpus", Runtime.getRuntime().availableProcessors());
|
||||
@@ -3504,8 +3498,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss的时间值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static String now() {
|
||||
return String.format(format1, System.currentTimeMillis());
|
||||
return Times.now();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3513,8 +3508,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss.fff的时间值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static String nowMillis() {
|
||||
return String.format(format2, System.currentTimeMillis());
|
||||
return Times.nowMillis();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3524,8 +3520,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 格式为yyyy-MM-dd HH:mm:ss的时间值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static String formatTime(long time) {
|
||||
return String.format(format1, time);
|
||||
return Times.formatTime(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3535,8 +3532,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 36进制时间值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static String format36time(long time) {
|
||||
return Long.toString(time, 36);
|
||||
return Times.format36time(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3544,8 +3542,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long midnight() {
|
||||
return midnight(System.currentTimeMillis());
|
||||
return Times.midnight();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3555,8 +3554,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long midnight(long time) {
|
||||
return (time + zoneRawOffset) / 86400000 * 86400000 - zoneRawOffset;
|
||||
return Times.midnight(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3564,9 +3564,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 20151231格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int today() {
|
||||
java.time.LocalDate today = java.time.LocalDate.now();
|
||||
return today.getYear() * 10000 + today.getMonthValue() * 100 + today.getDayOfMonth();
|
||||
return Times.today();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3574,9 +3574,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 151231格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int todayYYMMDD() {
|
||||
java.time.LocalDate today = java.time.LocalDate.now();
|
||||
return today.getYear() % 100 * 10000 + today.getMonthValue() * 100 + today.getDayOfMonth();
|
||||
return Times.todayYYMMDD();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3584,10 +3584,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 1512312359格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int todayYYMMDDHHmm() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() % 100 * 100_00_00_00 + today.getMonthValue() * 100_00_00 + today.getDayOfMonth() * 100_00
|
||||
+ today.getHour() * 100 + today.getMinute();
|
||||
return Times.todayYYMMDDHHmm();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3595,10 +3594,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 20151231235959格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long todayYYYYMMDDHHmmss() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() * 100_00_00_00_00L + today.getMonthValue() * 100_00_00_00 + today.getDayOfMonth() * 100_00_00
|
||||
+ today.getHour() * 100_00 + today.getMinute() * 100 + today.getSecond();
|
||||
return Times.todayYYYYMMDDHHmmss();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3606,10 +3604,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 151231235959格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long todayYYMMDDHHmmss() {
|
||||
java.time.LocalDateTime today = java.time.LocalDateTime.now();
|
||||
return today.getYear() % 100 * 100_00_00_00_00L + today.getMonthValue() * 100_00_00_00 + today.getDayOfMonth() * 100_00_00
|
||||
+ today.getHour() * 100_00 + today.getMinute() * 100 + today.getSecond();
|
||||
return Times.todayYYMMDDHHmmss();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3617,10 +3614,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 20151230格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int tomorrow() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
return cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.tomorrow();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3628,10 +3624,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 151230格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int tomorrowYYMMDD() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, 1);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.tomorrowYYMMDD();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3639,10 +3634,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 20151230格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int yesterday() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
return cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.yesterday();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3650,10 +3644,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 151230格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int yesterdayYYMMDD() {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.add(Calendar.DAY_OF_YEAR, -1);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.yesterdayYYMMDD();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3663,10 +3656,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int yyyyMMdd(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.yyyyMMdd(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3676,10 +3668,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int yyMMdd(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) % 100 * 10000 + (cal.get(Calendar.MONTH) + 1) * 100 + cal.get(Calendar.DAY_OF_MONTH);
|
||||
return Times.yyMMdd(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3689,10 +3680,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 16020223格式的int值
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static int yyMMDDHHmm(long time) {
|
||||
Calendar cal = Calendar.getInstance();
|
||||
cal.setTimeInMillis(time);
|
||||
return cal.get(Calendar.YEAR) % 100 * 100_00_00 + (cal.get(Calendar.MONTH) + 1) * 100_00 + cal.get(Calendar.DAY_OF_MONTH) * 100 + cal.get(Calendar.HOUR_OF_DAY);
|
||||
return Times.yyMMDDHHmm(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3702,12 +3692,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long monday(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.minusDays(ld.getDayOfWeek().getValue() - 1);
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
return Times.monday(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3717,12 +3704,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long sunday(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.plusDays(7 - ld.getDayOfWeek().getValue());
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
return Times.sunday(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3732,11 +3716,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long monthFirstDay(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate().withDayOfMonth(1);
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
return Times.monthFirstDay(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3746,12 +3728,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 毫秒数
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static long monthLastDay(long time) {
|
||||
ZoneId zid = ZoneId.systemDefault();
|
||||
Instant instant = Instant.ofEpochMilli(time);
|
||||
LocalDate ld = instant.atZone(zid).toLocalDate();
|
||||
ld = ld.withDayOfMonth(ld.lengthOfMonth());
|
||||
return ld.atStartOfDay(zid).toInstant().toEpochMilli();
|
||||
return Times.monthLastDay(time);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -3765,47 +3744,9 @@ public final class Utility {
|
||||
*
|
||||
* @return 时间格式化
|
||||
*/
|
||||
@Deprecated(since = "2.8.0")
|
||||
public static String formatTime(String format, int size, Object time) {
|
||||
if (size < 0) {
|
||||
int c = 0;
|
||||
if (!format.contains("%1$")) {
|
||||
for (char ch : format.toCharArray()) {
|
||||
if (ch == '%') {
|
||||
c++;
|
||||
}
|
||||
}
|
||||
}
|
||||
size = c;
|
||||
}
|
||||
if (size <= 1) {
|
||||
return String.format(format, time);
|
||||
}
|
||||
if (size == 2) {
|
||||
return String.format(format, time, time);
|
||||
}
|
||||
if (size == 3) {
|
||||
return String.format(format, time, time, time);
|
||||
}
|
||||
if (size == 4) {
|
||||
return String.format(format, time, time, time, time);
|
||||
}
|
||||
if (size == 5) {
|
||||
return String.format(format, time, time, time, time, time);
|
||||
}
|
||||
if (size == 6) {
|
||||
return String.format(format, time, time, time, time, time, time);
|
||||
}
|
||||
if (size == 7) {
|
||||
return String.format(format, time, time, time, time, time, time, time);
|
||||
}
|
||||
if (size == 8) {
|
||||
return String.format(format, time, time, time, time, time, time, time);
|
||||
}
|
||||
Object[] args = new Object[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
args[i] = time;
|
||||
}
|
||||
return String.format(format, args);
|
||||
return Times.formatTime(format, size, time);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -8,7 +8,7 @@ package org.redkale.test.service;
|
||||
import java.nio.channels.CompletionHandler;
|
||||
import org.redkale.annotation.Resource;
|
||||
import org.redkale.service.*;
|
||||
import org.redkale.util.Utility;
|
||||
import org.redkale.util.Times;
|
||||
|
||||
/**
|
||||
*
|
||||
@@ -31,19 +31,19 @@ public class CService implements Service {
|
||||
}
|
||||
|
||||
public RetResult<String> ccCurrentTime1(final String name) {
|
||||
String rs = "同步ccCurrentTime1: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
String rs = "同步ccCurrentTime1: " + name + ": " + Times.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.ccCurrentTime1++++同步方法1");
|
||||
return new RetResult(rs);
|
||||
}
|
||||
|
||||
public void ccCurrentTime2(final CompletionHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步ccCurrentTime2: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
String rs = "异步ccCurrentTime2: " + name + ": " + Times.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.ccCurrentTime2----异步方法2");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
}
|
||||
|
||||
public void mcCurrentTime3(final MyAsyncHandler<RetResult<String>, Void> handler, final String name) {
|
||||
String rs = "异步mcCurrentTime3: " + name + ": " + Utility.formatTime(System.currentTimeMillis());
|
||||
String rs = "异步mcCurrentTime3: " + name + ": " + Times.formatTime(System.currentTimeMillis());
|
||||
System.out.println("执行了 CService.mcCurrentTime3----异步方法3");
|
||||
if (handler != null) handler.completed(new RetResult(rs), null);
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ package org.redkale.test.source;
|
||||
import java.io.Serializable;
|
||||
import org.redkale.persistence.*;
|
||||
import org.redkale.source.*;
|
||||
import org.redkale.util.Times;
|
||||
import org.redkale.util.Utility;
|
||||
|
||||
/**
|
||||
@@ -115,7 +116,7 @@ public class LoginRecord extends BaseEntity {
|
||||
LoginRecord record = new LoginRecord();
|
||||
long now = System.currentTimeMillis();
|
||||
record.setCreatetime(now); //设置创建时间
|
||||
record.setLoginid(Utility.format36time(now) + "-" + Utility.uuid()); //主键的生成规则
|
||||
record.setLoginid(Times.format36time(now) + "-" + Utility.uuid()); //主键的生成规则
|
||||
//.... 填充其他字段
|
||||
source.insert(record);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user