C#时区转换『转』

原地址:http://www.cnblogs.com/aarond/archive/2011/04/28/2031262.html

 

using System;

using System.Collections.ObjectModel;

using System.Globalization;



namespace ConsoleApp_0422

{

    class Program

    {

        static void Main(string[] args)

        {

            //将本地时间转换为美国标准中部时间

            DateTime dt = TimeZoneInfo.ConvertTimeToUtc(DateTime.Now, TimeZoneInfo.Local);

            Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));



            dt = TimeZoneInfo.ConvertTimeFromUtc(dt, TimeZoneInfo.FindSystemTimeZoneById("Central America Standard Time"));

            Console.WriteLine(dt.ToString(CultureInfo.InvariantCulture));



            //列举所有支持的时区列表

            ReadOnlyCollection<TimeZoneInfo> lst = TimeZoneInfo.GetSystemTimeZones();

            foreach (TimeZoneInfo tzi in lst)

            {

                Console.WriteLine(tzi.Id);

            }

        }

    }

}

 

你可能感兴趣的:(C#)