Note that there are some explanatory texts on larger screens.

plurals
  1. POZoned dateTime to UTC Time - LocalDateTimePattern throws exception
    primarykey
    data
    text
    <p>I am trying to obtain the UTC time from a zoned datetime using LocalDateTime pattern in NodaTime using the below code.</p> <pre class="lang-cs prettyprint-override"><code>public string getUtcTimeFromZonedTime(string dateTimeString, string timeZoneID, string dateTimePattern, bool isDateTime) { if (string.IsNullOrEmpty(dateTimePattern)) { if (isDateTime) { dateTimePattern = "M/dd/yyyy HH:mm:ss tt"; } else { dateTimePattern = "M/dd/yyyy"; } } var pattern = LocalDateTimePattern.CreateWithInvariantCulture(dateTimePattern); var parseResult = pattern.Parse(dateTimeString); if (!parseResult.Success) { // throw an exception or whatever you want to do } var localDateTime = parseResult.Value; var timeZone = DateTimeZoneProviders.Tzdb[timeZoneID]; // TODO: Consider how you want to handle ambiguous or "skipped" local date/time // values. For example, you might want InZoneStrictly, or provide your own custom // handler to InZone. var zonedDateTime = localDateTime.InZoneLeniently(timeZone); return zonedDateTime.ToDateTimeUtc().ToString(); } </code></pre> <p>I get an exception during Parsing during below mentioned scenarios- 1) If pattern is like "MM/dd/yyyy HH:mm:ss tt" and the DateTime string is something like "5/28/2013 1:02:ss PM" 2) If pattern is like "MM-dd-yyyy HH:mm:ss tt" and the DateTime string is something like "5/28/2013 1:02:ss PM"</p> <p>For the first case, it will work if I change my pattern to "M/dd/yyyy HH:mm:ss tt", but i will end up losing the leading zero. Second case will work if I change the pattern to "MM/dd/yyyy HH:mm:ss tt"</p> <p>Is there any alternative way for getting the UTC values or am I doing something wrong over here.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload