Mohadese Entezari
Mohadese Entezari

Reputation: 81

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

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

Upvotes: 8

Views: 11183

Answers (2)

akbar
akbar

Reputation: 773

Use this nuget:

Mapster.Protobuf.extension

It adds protobuf mappings to mapster

Upvotes: 0

Marc Gravell
Marc Gravell

Reputation: 1063824

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)

Upvotes: 11

Related Questions