java - 如何通过UTC偏移量获取时区?
问题描述
我有 UTC 偏移量 -05:00,我想通过偏移量获取时区名称。
ZoneOffset offset = ZoneOffset.of("-05:00");
System.out.println(offset.getId()); //prints -05:00
我想得到这样的结果:
America/Chicago
America/Eirunepe
Etc/GMT+5
Mexico/General
...
我想要现在偏移的时区-05:00
(而不是那些可能在一年中的另一个时间的时区)。
解决方案
是的,你可以做到,看看这个。
final List<ZoneId> timeZoneByUtc = ZoneId.getAvailableZoneIds().stream().map(ZoneId::of)
.filter(z -> z.getRules().getOffset(Instant.now()).equals(ZoneOffset.ofHours(-5)))
.collect(Collectors.toList());
推荐阅读
- python - 减去两个不同数据类型的python列表的元素
- image-processing - 如何使亮度和对比度设置适应热像仪以保持数据一致性?
- sharepoint-2013 - 通过 CSOM 更新的项目不会触发远程事件接收器
- android - 单击通知时未清除后台堆栈
- javascript - 带箭头的 D3 弯曲链接未出现在屏幕上
- python - python vsphere DRS组
- windows - 自动从 SVN 导出工作副本
- php - Laravel 请求仅在更改时更新唯一字段
- python - Groupby 两列并将不同的分位数打印为单独的列
- node.js - 需要在 mongodb 中比较 2 个不同的日期字段