Reputation: 11
I'm using a gRPC connection on the project I'm working on and am having a problem with converting selected Datetime
object to google.protobuf.Timestamp
every time I map Datetime to google.protobuf.Timestamp
the mapped result in the minimum value of the google.protobuf.Timestamp
which is (1970-01-01T00:00:00Z.)
Here's the mapping I'm using
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());
Upvotes: 1
Views: 3636
Reputation: 31
using Google.Protobuf.WellKnownTypes
,
Timestamp ts = Timestamp.FromDateTime(datetime)
Upvotes: 3