How do I convert from 'Google.Protobuf.WellKnownTypes.Timestamp to 'System.DateTime'

Viewed 3838

I want to map datetime in c# datetime in protobuf . Do you have any suggestion to do this?

1 Answers

If you mean the Google implementation: quite simply, FromDateTime and ToDateTime

Google.Protobuf.WellKnownTypes.Timestamp protoTimestamp 
    = Google.Protobuf.WellKnownTypes.Timestamp.FromDateTime(DateTime.Now);

(I add that qualification because protobuf-net also defines similarly named types, which have implicit conversion operators to/from DateTime)

Related