【发布时间】:2020-12-15 06:27:16
【问题描述】:
我正在处理的项目中使用 gRPC 连接,但在将选定的 Datetime 对象转换为 google.protobuf.Timestamp 时遇到问题
每次我将 Datetime 映射到 google.protobuf.Timestamp 时,映射的结果都是 google.protobuf.Timestamp 的最小值,即 (1970-01-01T00:00:00Z.)
这是我正在使用的映射
CreateMap<DateTime, Google.Protobuf.WellKnownTypes.Timestamp>().ConvertUsing(x => Timestamp.FromDateTime(DateTime.SpecifyKind(x, DateTimeKind.Utc)));
CreateMap<Google.Protobuf.WellKnownTypes.Timestamp, DateTime>().ConvertUsing(x => x.ToDateTime());
【问题讨论】:
-
问题:您使用的是 Google protobuf/grpc 实现,还是 protobuf-net?他们都将定义这种类型,但方式略有不同
-
导入“google/protobuf/timestamp.proto”;我在我的 proto 文件中使用它
-
两者都适用;让我换个说法 - 你这里有没有人可以运行的最小再现,显示你看到的结果?
标签: asp.net-core protocol-buffers grpc