i have straightforward notion want represent using noda time:
04/24/2015 4:00pm america/new_york
to create unambiguous representation, i've done following:
var _americanewyork = datetimezoneproviders.tzdb["america/new_york"]; var pattern = localdatetimepattern.createwithinvariantculture("m/d/yyyy h:mmtt"); var localtime = pattern.parse(formatteddatetime).value; var zoneddatetime = localtime.inzoneleniently(_easterntime); is there more concise way did above? feel should able 1 or 2 lines instead:
var unambiguous = new zoneddatetime(string texttoparse, datetimepattern pattern, string timezone); and maybe few overloads if want specify gap semantics when changes occur.
i'd you've got best approach @ moment - you're parsing right type, in you've got in text ("04/24/2015 4:00pm") local time. (if you've got "america/new_york" bit in there, should use zoneddatetimepattern.)
but can use zoneddatetimepattern anyway, appropriate resolver , template value:
var tzdb = datetimezoneproviders.tzdb; var pattern = zoneddatetimepattern.create( "m/d/yyyy h:mmtt", cultureinfo.invariantculture, resolvers.lenientresolver, tzdb, nodaconstants.unixepoch.inzone(tzdb["america/new_york"])); string text = "04/24/2015 4:00pm"; var zoned = pattern.parse(text).value; console.writeline(zoned); obviously that's more code start with, can reuse pattern multiple times.
as say, i'd stick you've got says you're trying do: parse localdatetime , resolve particular zone.