Created
December 22, 2015 15:14
-
-
Save betweenbrain/8885af32e9529fef02f3 to your computer and use it in GitHub Desktop.
C# Offset UTC by Int Console App
This file contains 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
//Current UTC time | |
DateTime timeUtc = DateTime.UtcNow; | |
Console.WriteLine("UTC is {0}", timeUtc); | |
// UTC offset as a +/- integer | |
Console.WriteLine("Enter an +/- integr to offset UTC:"); | |
int offset = Convert.ToInt32(Console.ReadLine()); | |
Console.WriteLine("Int offset is {0}", offset); | |
// Format UTC offset as hh:mm:ss | |
string offsetTime = offset.ToString("00") + ":00:00"; | |
Console.WriteLine("Int to dateTime {0}", offsetTime); | |
// Parse hh:mm:ss offset string as time | |
TimeSpan utcOffset = TimeSpan.Parse(offsetTime); | |
// Calculate time as offset UTC | |
DateTime newDateTime = timeUtc + utcOffset; | |
Console.WriteLine("UTC offset by {0} is {1}", utcOffset, newDateTime); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment