Created
October 5, 2015 02:17
-
-
Save bohdanszymanik/1a9484d26e681b28a49e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#r @"packages\NodaTime\lib\net35-Client\NodaTime.dll" | |
open NodaTime | |
SystemClock.Instance.Now | |
let pattern = NodaTime.Text.LocalDateTimePattern.CreateWithInvariantCulture("MM/dd/yyyy HH:mm") | |
pattern.Parse("11/05/2014 21:15") | |
let dt s = DateTime.ParseExact(s, "d/MM/yyyy h:mm:ss tt", CultureInfo.CurrentCulture) | |
let testdt = dt "30/08/2015 10:30:25 p.m." | |
testdt.Kind | |
// gives | |
// val it : DateTimeKind = Unspecified | |
DateTime.ParseExact("30/08/2015 10:30:25 p.m.", "d/MM/yyyy h:mm:ss tt", CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal) | |
// gives val it : DateTime = 31/08/2015 10:30:25 a.m. | |
DateTime.ParseExact("30/08/2015 10:30:25 p.m.", "d/MM/yyyy h:mm:ss tt", CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal).Kind | |
// gives DateTimeKind = Local | |
// so it parses the utc time to create a local time | |
// with the kind of date specified then we can convert to nodatime structure | |
let utcdate = DateTime.ParseExact("30/08/2015 10:30:25 p.m.", "d/MM/yyyy h:mm:ss tt", CultureInfo.CurrentCulture, DateTimeStyles.AssumeUniversal).ToUniversalTime() | |
Instant.FromDateTimeUtc( utcdate ) | |
// cf nodatime parsing | |
let t' = "15.01.2015" |> NodaTime.Text.LocalDateTimePattern.CreateWithInvariantCulture("dd.MM.yyyy").Parse | |
t'.Success | |
let txtToDate = NodaTime.Text.LocalDateTimePattern.CreateWithInvariantCulture("dd.MM.yyyy").Parse |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment