2013년 3월 4일 월요일

Local DateTime UTC 변환하기




Written by 김영일(Youngil Kim), C#.NET Developer

최근 다국어기반으로 솔루션개발을 하다보니까 시간정보를 현지에 맞게 설정해둘 필요가 있습니다. 이런 경우 UTC(Universal Time Coordinated / 협정 세계시)을 기준으로 타임존을 의식할 필요없이  정확한 현지 시간을 체크할 수 있습니다. 한국의 경우 +9:00입니다.

[UTCTimeCheck.cs]
using System;
using System.Collections.Generic;
using System.Text;
namespace UTCTimeCheck
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt = DateTime.UtcNow.AddHours(9);
            Console.WriteLine(dt.ToString("yyyy/MM/dd hh:mm:ss"));
        }
    }
}

거꾸로 구하려면 -9한다.
            DateTime dt = DateTime.UtcNow.AddHours(-9);

댓글 없음: