I’m attempting to parse user input with Noda Time.
Input:
- Date in the form of
YYYY-MM-DD - Hour
- Minute
- tz database time zone name (returned from Google’s Time Zone API)
I need to convert this data to UTC and to other time zones, also based on a tz database time zone name.
Currently I’m trying to make sense of the LocalDateTime and ZonedDateTime differences, but perhaps someone is able to show how to do this before I’d (hopefully) figure this out.
Your answer is pretty close to what I’d do – but if you have the date, hour and minute in separate strings, I’d use:
The only significant difference here is the parsing – I wouldn’t stick all the bits together; I’d just parse the strings separately. (I also prefer “early outs” for failures 🙂
You should note the meaning of
InZoneStrictlythough – do you definitely want to fail if the input local date/time is ambiguous?