# clock
**Repository Path**: ALI1416/clock
## Basic Information
- **Project Name**: clock
- **Description**: High Performance Clock 高性能时钟
- **Primary Language**: Java
- **License**: Apache-2.0
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 2
- **Forks**: 0
- **Created**: 2021-03-15
- **Last Updated**: 2025-11-05
## Categories & Tags
**Categories**: utils
**Tags**: None
## README
# High Performance Clock 高性能时钟
[](https://www.apache.org/licenses/LICENSE-2.0.txt)
[](https://openjdk.org/)
[](https://mvnrepository.com/artifact/cn.404z/clock)
[](https://github.com/ALI1416/clock/tags)
[](https://github.com/ALI1416/clock/archive/refs/heads/master.zip)
[](https://github.com/ALI1416/clock/actions/workflows/ci.yml)
[


](https://sonarcloud.io/summary/new_code?id=ALI1416_clock)
## 简介
此工具类在`高并发`下比`System.currentTimeMillis()`性能更高
## 依赖导入
```xml
cn.404z
clock
2.8.0
```
## 使用示例
代码
```java
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());
```
结果
```log
现在时间戳为: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]
```
更多请见[测试](./src/test)
## 性能比较
| 次数 | Clock.now()耗时 | System.currentTimeMillis()耗时 | 倍数 |
| ------ | --------------- | ------------------------------ | ------- |
| 100万 | 1毫秒 | 5毫秒 | 5.0倍 |
| 1000万 | 2毫秒 | 22毫秒 | 11.0倍 |
| 1亿 | 3毫秒 | 327毫秒 | 109.0倍 |
| 21亿 | 35毫秒 | 6720毫秒 | 192.0倍 |
## 更新日志
[点击查看](./CHANGELOG.md)
## 关于