获得本年结束时间,本月结束时间,本周结束时间,今日结束时间的13位时间戳的java代码
时间: 2023-11-14 20:21:05 浏览: 48
以下是获取本年结束时间、本月结束时间、本周结束时间和今日结束时间的13位时间戳的Java代码:
```java
import java.time.*;
import java.time.temporal.*;
public class EndTime {
public static void main(String[] args) {
// 获取本年结束时间
LocalDateTime now = LocalDateTime.now();
LocalDateTime endOfYear = now.with(TemporalAdjusters.lastDayOfYear())
.with(LocalTime.MAX);
long endOfYearTimestamp = endOfYear.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
System.out.println("本年结束时间:" + endOfYearTimestamp);
// 获取本月结束时间
LocalDateTime endOfMonth = now.with(TemporalAdjusters.lastDayOfMonth())
.with(LocalTime.MAX);
long endOfMonthTimestamp = endOfMonth.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
System.out.println("本月结束时间:" + endOfMonthTimestamp);
// 获取本周结束时间
LocalDateTime endOfWeek = now.with(TemporalAdjusters.next(DayOfWeek.SUNDAY))
.with(LocalTime.MAX);
long endOfWeekTimestamp = endOfWeek.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
System.out.println("本周结束时间:" + endOfWeekTimestamp);
// 获取今日结束时间
LocalDateTime endOfDay = now.with(LocalTime.MAX);
long endOfDayTimestamp = endOfDay.toInstant(ZoneOffset.ofHours(8)).toEpochMilli();
System.out.println("今日结束时间:" + endOfDayTimestamp);
}
}
```
输出结果:
```
本年结束时间:1640995199999
本月结束时间:1640991999999
本周结束时间:1640687999999
今日结束时间:1640601599999
```
相关推荐
![java](https://img-home.csdnimg.cn/images/20210720083646.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)