SoFunction
Updated on 2025-03-05

Implementation method of converting UTC time to JST time in C#

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

  1. Get the current UTC time:

    • useGet the current UTC time.
  2. Get JST time zone information:

    • use("Tokyo Standard Time")Get JST time zone information.Tokyo Standard TimeIt is the identifier of JST in Windows system.
  3. Convert UTC time to JST time:

    • useMethod converts UTC time to JST time.

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 supportTimeZoneInfoClass andTokyo Standard TimeTime 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!