How to control timezone formatting in System.Xml.Serialization or at runtime?

I am developing a C # .Net application that runs on a system located in the Central Time Zone. The application receives information from a third party using the API provided by it. I used WSDL to create the code that the application accesses the API using ... their reporting API allows you to determine the start date and end date of the report. These are the C # DateTime and XSD: dateTime fields. Now, when I set the start and end dates of the date and let the API create SOAP messages, the dates do not always include the time zone unless I set the date fields using the ToLocalTime method; however, the method will create DateTime fields in the Central time zone (CST), but I need to create these fields in the Pacific time zone (PST). If I set my machine time for PST, everything will be fine ... but, of course, this causes other time problems.What methods can I use to control DateTime formatting? Alternatively, is there an app setting that can be installed in C # that allows you to manage your time zone?

+3
source share
2 answers

I think you can achieve this using System.TimeZoneInfo . For instance:

TimeZoneInfo.ConvertTime(myLocalTime, TimeZoneInfo.FindSystemTimeZoneById("Pacific Standard Time"));
0
source

I think you have two options. Obviously, what you can do will depend on how the target system processes the date it receives.

1- Convert date and time to the target time zone and send a request without time zone information. This assumes that the target system will accept a date and time that does not contain time zone information as being in the PST time zone.

2- DateTimeOffset. .

, 2.

0

Source: https://habr.com/ru/post/1747759/


All Articles