Protobuf C# Message Translation to JAVA

旧城冷巷雨未停 提交于 2019-12-06 06:53:23

Looking at bcl.proto, it should be pretty straightforward. Create a Map<DateTime.TimeSpanScale, TimeUnit> in the obvious way, then:

public static Date toDate(bcl.DateTime proto) {
    TimeUnit unit = SCALE_TO_UNIT_MAP.get(proto.getScale());
    if (unit == null) {
        throw new IllegalArgumentException("Invalid scale: " + proto.getScale());
    }
    long millis = unit.toMillis(proto.getValue());
    return new Date(millis);
}

You could use Joda Time's DateTime type in exactly the same way, as it has a constructor accepting a long too. (You might want to think about which time zone to specify though...)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!