-1

I'm making a C# windows form application. There is a DateTimePicker tool on the application and the tool's format is MM/dd/yyyy hh:mm:ss tt. For example, the date looks like this on the application: 07/28/2021 09:10:50 AM

I want to convert that date to milliseconds depending on UTC, and send that milliseconds to the server. I also need to do the opposite. When I receive the milliseconds from the server (UTC), I need to convert it to the format of the DateTimePicker (MM/dd/yyyy hh:mm:ss tt). I don't need to convert the date to the local time when I receive the milliseconds from the server. Everything will depend on UTC. How can I do that?

  • 1
    Would have thought that a date and time picker would give you a native DateTime object! – phuzi Jul 28 '21 at 09:20

1 Answers1

0

Use ParseExact to parse a specific format https://learn.microsoft.com/en-us/dotnet/api/system.datetime.parseexact?redirectedfrom=MSDN&view=net-5.0#overloads

Be aware that depending on the tool/version using to accept the datetime, it may assume local-time/UTC so you may want to check the DateTime.Kind property. https://github.com/dotnet/aspnetcore/issues/11584

If you are having trouble leverage DateTimeOffset to accept the value from the server and then pull out the raw DateTime from there using:

DateTimeOffset.DateTime
DisplayName
  • 196
  • 3
  • 12