Created
March 28, 2019 04:25
-
-
Save MinChanSike/11ee7b3640f42221a1d1010836a8f5de to your computer and use it in GitHub Desktop.
Date Time vs DateTimeOffset
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
var now = DateTime.Now; | |
var nowUTC = now.ToUniversalTime(); | |
var nowOffset = new DateTimeOffset(now); | |
var nowUTCOffset = new DateTimeOffset(nowUTC); | |
DateTimeOffset nowWithOffset = now; | |
now.Dump("Now"); | |
nowUTC.Dump("Now UTC"); | |
nowOffset.Dump("Now Offset"); | |
nowUTCOffset.Dump("Now UTC Offset"); | |
nowWithOffset.Dump("Now with offset object"); | |
nowWithOffset.UtcDateTime.Dump("Offset to UTC"); | |
nowWithOffset.LocalDateTime.Dump("Offset to Local"); | |
DateTime utcDt = DateTime.SpecifyKind(now, DateTimeKind.Utc); | |
DateTime localDt = DateTime.SpecifyKind(now, DateTimeKind.Local); | |
DateTimeOffset utcDtff = DateTime.SpecifyKind(now, DateTimeKind.Utc); | |
DateTimeOffset localDtff = DateTime.SpecifyKind(now, DateTimeKind.Local); | |
utcDt.Dump(); localDt.Dump(); | |
utcDtff.Dump(); localDtff.Dump(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment