7

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

1 Answers1

8

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)

Jeff Maass
  • 3,632
  • 3
  • 26
  • 30
Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900