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

2

8

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

Islas answered 15/9, 2020 at 9:55 Comment(3)
Did you try to reach the documentation?Czechoslovak
Yes but I didn't reach a conclusion, Do you any resources about it ?Islas
Can you post the links to the documentation you have read and also add some code lines on the conversion, this way others can help you check for issues.Balliol
A
11

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)

Albi answered 15/9, 2020 at 11:6 Comment(1)
tnx for your helpIslas
P
0

Use this nuget:

Mapster.Protobuf.extension

It adds protobuf mappings to mapster

Pursue answered 14/6 at 4:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.