jjava获得本日,本月,本周,本年开始时间的13位时间戳
时间: 2024-05-05 11:16:20 浏览: 70
java获取今天、昨天、近一周、本周、本月时间段
获取本日开始时间戳:
```java
long startOfDay = LocalDate.now().atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000;
```
获取本月开始时间戳:
```java
long startOfMonth = LocalDate.now().withDayOfMonth(1).atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000;
```
获取本周开始时间戳:
```java
long startOfWeek = LocalDate.now().with(TemporalAdjusters.previousOrSame(DayOfWeek.MONDAY)).atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000;
```
获取本年开始时间戳:
```java
long startOfYear = LocalDate.now().withDayOfYear(1).atStartOfDay().toEpochSecond(ZoneOffset.UTC) * 1000;
```
阅读全文