When testing the unit test involving time zone changes, the DateTime object must be created in a specific non -local time zone.
Question:
How to create DateTime objects with a specific time zone (such as PST) without relying on local time zones or UTC time zones?
Answer:
Datetime constructor can only allow the use of local time zones, UTC time zones or unspecified options. Therefore, we can use timezoneinfo. Solution:
In order to create DateTime objects with a specific time zone (such as PST), please consider achieving custom structure:
This structure allows you to create DateTime objects with a specific time zone and access its UTC time and local time. Use the expression body attribute to simplify the code.
The above is the detailed content of How to Create a DateTime Object in a Specific Time Zone (e.g., PST) in C# Without Using Local or UTC?. For more information, please follow other related articles on the PHP Chinese website!