How to convert .Net System.DateTime to google Protobuf TimeStamp when forming a protobuf message?
Use protobuf's Timestamp.FromDateTime. Following is the example of converting DateTime.Now to proto timestamp type.
Google.Protobuf.WellKnownTypes.Timestamp protoTimestamp
= Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.Now);
This is the official reference link
Timestamp only works with UTC. So you may do this:
Timestamp.FromDateTime(DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With