Sample code
Here is a complete example showing how to convert UTC time to JST time.
Main program code
csharp
using System; class Program { static void Main() { // Get the current UTC time DateTime utcTime = ; ($"UTC Time: {utcTime}"); // Get JST time zone information TimeZoneInfo jstTimeZone = ("Tokyo Standard Time"); // Convert UTC time to JST time DateTime jstTime = (utcTime, jstTimeZone); ($"JST Time: {jstTime}"); } }
explain
-
Get the current UTC time:
- use
Get the current UTC time.
- use
-
Get JST time zone information:
- use
("Tokyo Standard Time")
Get JST time zone information.Tokyo Standard Time
It is the identifier of JST in Windows system.
- use
-
Convert UTC time to JST time:
- use
Method converts UTC time to JST time.
- use
Running effect
Run the above code and the output result is as follows:
Complete example
The following is a complete code example, including getting the current UTC time, converting it to JST time and outputting the result.
Complete code
csharp
using System; class Program { static void Main() { // Get the current UTC time DateTime utcTime = ; ($"UTC Time: {utcTime}"); // Get JST time zone information TimeZoneInfo jstTimeZone = ("Tokyo Standard Time"); // Convert UTC time to JST time DateTime jstTime = (utcTime, jstTimeZone); ($"JST Time: {jstTime}"); } }
Running environment
Ensure your development environment supportTimeZoneInfo
Class andTokyo Standard Time
Time zone identifier. Most modern Windows systems support these features.
With the above method, you can easily convert UTC time to JST time in C#.
This is the article about the implementation method of converting UTC time to JST time in C#. For more related content on C#, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!