Last active
August 29, 2015 14:26
-
-
Save anakahala/c692bd40cfbda8d32b75 to your computer and use it in GitHub Desktop.
UTC時間変換
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| using System.Threading.Tasks; | |
| namespace ConsoleApplication6 | |
| { | |
| class Program | |
| { | |
| public static void Main() | |
| { | |
| TimeSpan ts = new TimeSpan(-1000); | |
| var timeZoneId = "Tokyo Standard Time"; | |
| Console.WriteLine("{0} Time {1}", "UTC", ConvertTimeToUtc(new DateTime(2015, 7, 26, 11, 11, 12), timeZoneId)); | |
| Console.WriteLine("{0} {1}", timeZoneId, | |
| ConvertTimeFromUtc(ConvertTimeToUtc(new DateTime(2015, 7, 26, 11, 11, 12), timeZoneId), timeZoneId)); | |
| Console.ReadKey(); | |
| } | |
| /// <summary> | |
| /// UTC時間から指定したタイムゾーンの時間に変換 | |
| /// </summary> | |
| /// <param name="dateTime"></param> | |
| /// <param name="timeZoneId"></param> | |
| /// <returns></returns> | |
| private static DateTime ConvertTimeFromUtc(DateTime dateTime, string timeZoneId) | |
| { | |
| return ConvertTimeFromUtc(dateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZoneId)); | |
| } | |
| /// <summary> | |
| /// UTC時間から指定したタイムゾーンの時間に変換 | |
| /// </summary> | |
| /// <param name="dateTime"></param> | |
| /// <param name="timeZoneInfo"></param> | |
| /// <returns></returns> | |
| private static DateTime ConvertTimeFromUtc(DateTime dateTime, TimeZoneInfo timeZoneInfo) | |
| { | |
| return TimeZoneInfo.ConvertTimeFromUtc(dateTime, timeZoneInfo); | |
| } | |
| /// <summary> | |
| /// UTC時間に変換 | |
| /// </summary> | |
| /// <param name="dateTime"></param> | |
| /// <param name="timeZoneId"></param> | |
| /// <returns></returns> | |
| private static DateTime ConvertTimeToUtc(DateTime dateTime, string timeZoneId) | |
| { | |
| return ConvertTimeToUtc(dateTime, TimeZoneInfo.FindSystemTimeZoneById(timeZoneId)); | |
| } | |
| /// <summary> | |
| /// UTC時間に変換 | |
| /// </summary> | |
| /// <param name="dateTime"></param> | |
| /// <param name="timeZoneInfo"></param> | |
| /// <returns></returns> | |
| private static DateTime ConvertTimeToUtc(DateTime dateTime, TimeZoneInfo timeZoneInfo) | |
| { | |
| return TimeZoneInfo.ConvertTimeToUtc(dateTime, timeZoneInfo); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment