c# - DateTime Unspecified Kind -
on msdn defined unspecified kind as:
so if kind unspecified datetime utc, on same page (given example):
class sample { public static void main() { datetime savenow = datetime.now; mydt = datetime.specifykind(savenow, datetimekind.unspecified); display("unspecified: .....", mydt); } public static string datepatt = @"m/d/yyyy hh:mm:ss tt"; public static void display(string title, datetime inputdt) { datetime dispdt = inputdt; string dtstring; dtstring = dispdt.tostring(datepatt); console.writeline("{0} {1}, kind = {2}", title, dtstring, dispdt.kind); dispdt = inputdt.tolocaltime(); dtstring = dispdt.tostring(datepatt); console.writeline(" tolocaltime: {0}, kind = {1}", dtstring, dispdt.kind); dispdt = inputdt.touniversaltime(); dtstring = dispdt.tostring(datepatt); console.writeline(" touniversaltime: {0}, kind = {1}", dtstring, dispdt.kind); console.writeline(); } } }
giving output as:
unspecified: ..... 5/6/2005 02:34:42 pm, kind = unspecified
tolocaltime: 5/6/2005 07:34:42 am, kind = local
touniversaltime: 5/6/2005 09:34:42 pm, kind = utc
so, issue have is, if unspecified utc why utc utc conversion change datetime object value?
no, unspecified , utc different - page you're quoting from tolocaltime
. point if call tolocaltime
using "unspecified" datetime
, value treated as if in utc.
likewise if call touniversaltime
using "unspecified" datetime
, value treated as if in system local time zone.
frankly sort of thing why i dislike datetime
rather lot. if you, i'd use noda time instead, separates concepts out different types entirely, removing lot of confusion. (there more types know about, each 1 represents single concept.) i'm biased though...
Comments
Post a Comment