Skip to content

ALI1416/clock

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

High Performance Clock 高性能时钟

License Java Support Maven Central Tag Repo Size

Java CI Coverage Reliability Rating Maintainability Rating Security Rating

简介

此工具类在高并发下比System.currentTimeMillis()性能更高

依赖导入

<dependency>
  <groupId>cn.404z</groupId>
  <artifactId>clock</artifactId>
  <version>2.5.0</version>
</dependency>

使用示例

代码

log.info("现在时间戳为:{}", Clock.now());
log.info("现在Date为:{}", Clock.date());
log.info("现在Timestamp为:{}", Clock.timestamp());
log.info("现在Calendar为:{}", Clock.calendar());
log.info("现在Instant为:{}", Clock.instant());
log.info("现在LocalDateTime为:{}", Clock.localDateTime());
log.info("现在OffsetDateTime为:{}", Clock.offsetDateTime());
log.info("现在ZonedDateTime为:{}", Clock.zonedDateTime());

结果

现在时间戳为:1703313006732
现在Date为:Sat Dec 23 14:30:06 CST 2023
现在Timestamp为:2023-12-23 14:30:06.748
现在Calendar为:java.util.GregorianCalendar[time=1703313006748,areFieldsSet=true,areAllFieldsSet=true,lenient=true,zone=sun.util.calendar.ZoneInfo[id="Asia/Shanghai",offset=28800000,dstSavings=0,useDaylight=false,transitions=31,lastRule=null],firstDayOfWeek=1,minimalDaysInFirstWeek=1,ERA=1,YEAR=2023,MONTH=11,WEEK_OF_YEAR=51,WEEK_OF_MONTH=4,DAY_OF_MONTH=23,DAY_OF_YEAR=357,DAY_OF_WEEK=7,DAY_OF_WEEK_IN_MONTH=4,AM_PM=1,HOUR=2,HOUR_OF_DAY=14,MINUTE=30,SECOND=6,MILLISECOND=748,ZONE_OFFSET=28800000,DST_OFFSET=0]
现在Instant为:2023-12-23T06:30:06.748Z
现在LocalDateTime为:2023-12-23T14:30:06.748
现在OffsetDateTime为:2023-12-23T14:30:06.748+08:00
现在ZonedDateTime为:2023-12-23T14:30:06.748+08:00[Asia/Shanghai]

更多请见测试

性能比较

次数 Clock.now()耗时 System.currentTimeMillis()耗时 倍数
100万 1毫秒 5毫秒 5.0倍
1000万 2毫秒 22毫秒 11.0倍
1亿 3毫秒 327毫秒 109.0倍
21亿 35毫秒 6720毫秒 192.0倍

更新日志

点击查看

关于

About

About

High Performance Clock 高性能时钟

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Languages