首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何将Google proto时间戳转换为Java LocalDate?

如何将Google proto时间戳转换为Java LocalDate?
EN

Stack Overflow用户
提问于 2018-10-04 19:24:03
回答 1查看 19.4K关注 0票数 16

我们需要将Google Proto buffer时间戳转换为正常日期。在这种情况下,有没有办法把Google Proto buffer的时间戳直接转换成一个Java LocalDate呢?

EN

回答 1

Stack Overflow用户

发布于 2020-03-26 12:59:04

PubsubMessage pubsubMessage = message.getPubsubMessage();
String data = pubsubMessage.getData().toStringUtf8();
//System.out.println(pubsubMessage.getMessageId());
Timestamp timestamp = pubsubMessage.getPublishTime();
//System.out.println(timestamp);
Instant instant =  Instant.ofEpochSecond(timestamp.getSeconds() , 
timestamp.getNanos());
ZoneId z = ZoneId.of("America/Montreal");
ZonedDateTime zdt = instant.atZone(z);
LocalDateTime ldt = zdt.toLocalDateTime();
System.out.println("today's date==> "+ldt.getDayOfMonth()); 

上面的代码肯定会起作用。

票数 -1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52645487

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档