Reputation: 973
How to convert .Net System.DateTime to google Protobuf TimeStamp when forming a protobuf message?
Upvotes: 7
Views: 4937
Reputation: 6528
Timestamp only works with UTC. So you may do this:
Timestamp.FromDateTime(DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc)));
Upvotes: 4
Reputation: 973
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
Upvotes: 10