Skip to content

Instantly share code, notes, and snippets.

@MinChanSike
Created March 28, 2019 04:25
Show Gist options
  • Save MinChanSike/11ee7b3640f42221a1d1010836a8f5de to your computer and use it in GitHub Desktop.
Save MinChanSike/11ee7b3640f42221a1d1010836a8f5de to your computer and use it in GitHub Desktop.
Date Time vs DateTimeOffset
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