From 0b09e6006e0a83b52fa6aa99080c2187d2f24525 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Sat, 15 Jan 2022 13:27:37 -0800 Subject: [PATCH] DateTimeOffset F# snippets --- .../DateTimeOffset.ParseExact/fs.fsproj | 10 + .../parseexact-iso8601-2.fs | 87 +++++ .../parseexact-iso8601.fs | 28 ++ .../DateTimeOffset.TryParseExact/fs.fsproj | 9 + .../tryparseexacto8601-2.fs | 84 +++++ .../fs/Constructors.fs | 149 ++++++++ .../fs/fs.fsproj | 9 + .../fs/FileTime.fs | 111 ++++++ .../fs/fs.fsproj | 9 + .../fs/Methods.fs | 294 +++++++++++++++ .../fs/Methods2.fs | 26 ++ .../fs/Methods3.fs | 27 ++ .../fs/fs.fsproj | 11 + .../fs/Operators.fs | 185 ++++++++++ .../fs/fs.fsproj | 9 + .../fs/ParseExamples.fs | 67 ++++ .../system.DateTimeOffset.Parse/fs/fs.fsproj | 9 + .../fs/ParseExact.fs | 169 +++++++++ .../fs/fs.fsproj | 9 + .../fs/Properties.fs | 343 ++++++++++++++++++ .../fs/fs.fsproj | 9 + .../system.DateTimeOffset.Syntax/fs/Syntax.fs | 50 +++ .../system.DateTimeOffset.Syntax/fs/fs.fsproj | 9 + .../fs/ToOffset.fs | 47 +++ .../fs/fs.fsproj | 9 + .../fs/ToString.fs | 135 +++++++ .../fs/fs.fsproj | 9 + .../fs/TryParse.fs | 83 +++++ .../fs/fs.fsproj | 9 + .../fs/TryParseExact.fs | 115 ++++++ .../fs/fs.fsproj | 9 + .../system.DateTimeOffset.Type/fs/Type.fs | 20 + .../system.DateTimeOffset.Type/fs/fs.fsproj | 9 + .../system.datetimeoffset.now/fs/fs.fsproj | 9 + .../system.datetimeoffset.now/fs/now1.fs | 32 ++ ...t.tostring.argumentoutofrangeexception1.fs | 18 + ...t.tostring.argumentoutofrangeexception2.fs | 28 ++ ...t.tostring.argumentoutofrangeexception3.fs | 28 ++ ...t.tostring.argumentoutofrangeexception4.fs | 18 + .../fs/fs.fsproj | 12 + .../fs/fs.fsproj | 9 + .../fs/tounixtimeseconds1.fs | 20 + xml/System/DateTimeOffset.xml | 87 +++++ 43 files changed, 2419 insertions(+) create mode 100644 samples/snippets/fsharp/System/DateTimeOffset.ParseExact/fs.fsproj create mode 100644 samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.fs create mode 100644 samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.fs create mode 100644 samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/fs.fsproj create mode 100644 samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs diff --git a/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/fs.fsproj b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/fs.fsproj new file mode 100644 index 00000000000..b98f7ed9b54 --- /dev/null +++ b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.fs b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.fs new file mode 100644 index 00000000000..3b3ed23cb9d --- /dev/null +++ b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.fs @@ -0,0 +1,87 @@ +module parseexact_iso8601_2 + +open System +open System.Globalization + +let dateStrings = + [| "2018-08-18T12:45:16.0000000Z" + "2018/08/18T12:45:16.0000000Z" + "2018-18-08T12:45:16.0000000Z" + "2018-08-18T12:45:16.0000000" + " 2018-08-18T12:45:16.0000000Z " + "2018-08-18T12:45:16.0000000+02:00" + "2018-08-18T12:45:16.0000000-07:00" |] + +let parseWithISO8601 dateStrings styles = + printfn $"Parsing with {styles}:" + for dateString in dateStrings do + try + let date = DateTimeOffset.ParseExact(dateString, "O", null, styles) + printfn $""" {dateString,-35} --> {date.ToString "yyyy-MM-dd HH:mm:ss.FF zzz"}""" + with :? FormatException -> + printfn $" FormatException: Unable to convert '{dateString}'" + +parseWithISO8601 dateStrings DateTimeStyles.None +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AllowWhiteSpaces +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AdjustToUniversal +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AssumeLocal +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AssumeUniversal + + +// The example displays the following output: +// Parsing with None: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AllowWhiteSpaces: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AdjustToUniversal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 19:45:16 +00:00 +// FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 10:45:16 +00:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 19:45:16 +00:00 +// +// ----- +// +// Parsing with AssumeLocal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AssumeUniversal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 \ No newline at end of file diff --git a/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.fs b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.fs new file mode 100644 index 00000000000..82438778627 --- /dev/null +++ b/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.fs @@ -0,0 +1,28 @@ +module parseexact_iso8601 + +open System + +let dateStrings = + [ "2018-08-18T12:45:16.0000000Z" + "2018/08/18T12:45:16.0000000Z" + "2018-18-08T12:45:16.0000000Z" + " 2018-08-18T12:45:16.0000000Z " + "2018-08-18T12:45:16.0000000+02:00" + "2018-08-18T12:45:16.0000000-07:00" ] + +for dateString in dateStrings do + try + let date = + DateTimeOffset.ParseExact(dateString, "O", null) + + printfn $"""{dateString, -35} --> {date.ToString "yyyy-MM-dd HH:mm:ss.FF zzz"}""" + with :? FormatException -> printfn $"FormatException: Unable to convert '{dateString}'" + + +// The example displays the following output: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// FormatException: Unable to convert '2018/08/18T12:45:16.0000000Z' +// FormatException: Unable to convert '2018-18-08T12:45:16.0000000Z' +// FormatException: Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 diff --git a/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/fs.fsproj b/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/fs.fsproj new file mode 100644 index 00000000000..6b742d90a67 --- /dev/null +++ b/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs b/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs new file mode 100644 index 00000000000..cd881c4b586 --- /dev/null +++ b/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs @@ -0,0 +1,84 @@ +open System +open System.Globalization + +let parseWithISO8601 dateStrings styles = + printfn $"Parsing with {styles}:" + for dateString in dateStrings do + match DateTimeOffset.TryParseExact(dateString, "O", null, styles) with + | true, date -> + printfn $""" {dateString,-35} --> {date.ToString "yyyy-MM-dd HH:mm:ss.FF zzz"}""" + | _ -> + printfn $" Unable to convert '{dateString}'" + +let dateStrings = + [ "2018-08-18T12:45:16.0000000Z" + "2018/08/18T12:45:16.0000000Z" + "2018-18-08T12:45:16.0000000Z" + "2018-08-18T12:45:16.0000000" + " 2018-08-18T12:45:16.0000000Z " + "2018-08-18T12:45:16.0000000+02:00" + "2018-08-18T12:45:16.0000000-07:00" ] + +parseWithISO8601 dateStrings DateTimeStyles.None +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AllowWhiteSpaces +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AdjustToUniversal +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AssumeLocal +printfn "\n-----\n" +parseWithISO8601 dateStrings DateTimeStyles.AssumeUniversal + +// The example displays the following output: +// Parsing with None: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// Unable to convert '2018/08/18T12:45:16.0000000Z' +// Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AllowWhiteSpaces: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// Unable to convert '2018/08/18T12:45:16.0000000Z' +// Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AdjustToUniversal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// Unable to convert '2018/08/18T12:45:16.0000000Z' +// Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 19:45:16 +00:00 +// Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 10:45:16 +00:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 19:45:16 +00:00 +// +// ----- +// +// Parsing with AssumeLocal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// Unable to convert '2018/08/18T12:45:16.0000000Z' +// Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 -07:00 +// Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 +// +// ----- +// +// Parsing with AssumeUniversal: +// 2018-08-18T12:45:16.0000000Z --> 2018-08-18 12:45:16 +00:00 +// Unable to convert '2018/08/18T12:45:16.0000000Z' +// Unable to convert '2018-18-08T12:45:16.0000000Z' +// 2018-08-18T12:45:16.0000000 --> 2018-08-18 12:45:16 +00:00 +// Unable to convert ' 2018-08-18T12:45:16.0000000Z ' +// 2018-08-18T12:45:16.0000000+02:00 --> 2018-08-18 12:45:16 +02:00 +// 2018-08-18T12:45:16.0000000-07:00 --> 2018-08-18 12:45:16 -07:00 diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs new file mode 100644 index 00000000000..747dcb453b4 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs @@ -0,0 +1,149 @@ +open System +open System.Globalization + +let constructWithDateTime () = + // + let localNow = DateTime.Now + let localOffset = DateTimeOffset localNow + printfn $"{localOffset}" + + let utcNow = DateTime.UtcNow + let utcOffset = DateTimeOffset utcNow + printfn "{utcOffset}" + + let unspecifiedNow = DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified) + let unspecifiedOffset = DateTimeOffset unspecifiedNow + printfn $"{unspecifiedOffset}" + + // The code produces the following output if run on Feb. 23, 2007, on + // a system 8 hours earlier than UTC: + // 2/23/2007 4:21:58 PM -08:00 + // 2/24/2007 12:21:58 AM +00:00 + // 2/23/2007 4:21:58 PM -08:00 + // + +let constructWithTicks () = + // + let dateWithoutOffset = DateTime(2007, 7, 16, 13, 32, 00) + let timeFromTicks = DateTimeOffset(dateWithoutOffset.Ticks, TimeSpan(-5, 0, 0)) + printfn $"{timeFromTicks}" + // The code produces the following output: + // 7/16/2007 1:32:00 PM -05:00 + // + +let constructWithDateAndOffset () = + // + let localTime = DateTime(2007, 07, 12, 06, 32, 00) + let dateAndOffset = DateTimeOffset(localTime, TimeZoneInfo.Local.GetUtcOffset localTime) + printfn $"{dateAndOffset}" + // The code produces the following output: + // 7/12/2007 6:32:00 AM -07:00 + // + +let constructNonLocalWithLocalTicks () = + // + let localTime = DateTime.Now + let nonLocalDateWithOffset = DateTimeOffset(localTime.Ticks, TimeSpan(2, 0, 0)) + printfn $"{nonLocalDateWithOffset}" + // The code produces the following output if run on Feb. 23, 2007: + // 2/23/2007 4:37:50 PM +02:00 + // + +let constructWithDateElements () = + // + let specificDate = DateTime(2008, 5, 1, 06, 32, 00) + let offsetDate = DateTimeOffset(specificDate.Year, + specificDate.Month, + specificDate.Day, + specificDate.Hour, + specificDate.Minute, + specificDate.Second, + TimeSpan(-5, 0, 0)) + printfn $"Current time: {offsetDate}" + printfn $"Corresponding UTC time: {offsetDate.UtcDateTime}" + // The code produces the following output: + // Current time: 5/1/2008 6:32:00 AM -05:00 + // Corresponding UTC time: 5/1/2008 11:32:00 AM + // + +let constructWithDateElements2 () = + // + let specificDate = DateTime(2008, 5, 1, 6, 32, 05) + let offsetDate = DateTimeOffset(specificDate.Year - 1, + specificDate.Month, + specificDate.Day, + specificDate.Hour, + specificDate.Minute, + specificDate.Second, + 0, + TimeSpan(-5, 0, 0)) + printfn $"Current time: {offsetDate}" + printfn $"Corresponding UTC time: {offsetDate.UtcDateTime}" + // The code produces the following output: + // Current time: 5/1/2007 6:32:05 AM -05:00 + // Corresponding UTC time: 5/1/2007 11:32:05 AM + // + +let constructWithDateElements3 () = + // + let fmt = "dd MMM yyyy HH:mm:ss" + let thisDate = DateTime(2007, 06, 12, 19, 00, 14, 16) + let offsetDate = DateTimeOffset(thisDate.Year, + thisDate.Month, + thisDate.Day, + thisDate.Hour, + thisDate.Minute, + thisDate.Second, + thisDate.Millisecond, + TimeSpan(2, 0, 0)) + printfn $"Current time: {offsetDate.ToString fmt}:{offsetDate.Millisecond}" + // The code produces the following output: + // Current time: 12 Jun 2007 19:00:14:16 + // + +let constructWithCalendar () = + // + // Instantiate DateTimeOffset with Hebrew calendar + let year = 5770 + let cal = HebrewCalendar() + let fmt = CultureInfo "he-IL" + fmt.DateTimeFormat.Calendar <- cal + let dateInCal = DateTimeOffset(year, 7, 12, + 15, 30, 0, 0, + cal, + TimeSpan(2, 0, 0)) + // Display the date in the Hebrew calendar + printfn $"Date in Hebrew Calendar: {dateInCal.ToString fmt:g}" + // Display the date in the Gregorian calendar + printfn $"Date in Gregorian Calendar: {dateInCal:g}\n" + + // Instantiate DateTimeOffset with Hijri calendar + let year = 1431 + let cal = HijriCalendar() + let fmt = CultureInfo "ar-SA" + fmt.DateTimeFormat.Calendar <- cal + let dateInCal = DateTimeOffset(year, 7, 12, + 15, 30, 0, 0, + cal, + TimeSpan(2, 0, 0)) + // Display the date in the Hijri calendar + printfn $"Date in Hijri Calendar: {dateInCal.ToString fmt:g}" + // Display the date in the Gregorian calendar + printfn $"Date in Gregorian Calendar: {dateInCal:g}\n" + // + +constructWithDateTime () +printfn "" +constructWithTicks () +printfn "" +constructWithDateAndOffset () +printfn "" +constructNonLocalWithLocalTicks () +printfn "" +constructWithDateElements () +printfn "" +constructWithDateElements2 () +printfn "" +constructWithDateElements3 () +printfn "" +constructWithCalendar () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/fs.fsproj new file mode 100644 index 00000000000..a05323af32c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs new file mode 100644 index 00000000000..a7d7d6a1bb6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs @@ -0,0 +1,111 @@ +// +open System +open System.IO +open System.Runtime.InteropServices +open FSharp.NativeInterop + +[] +type FileTime = + val dwLowDateTime: uint + val dwHighDateTime: uint + + static member ToLong(fileTime: FileTime) = + // Convert 4 high-order bytes to a byte array + let mutable highBytes = BitConverter.GetBytes fileTime.dwHighDateTime + + // Resize the array to 8 bytes (for a Long) + Array.Resize(&highBytes, 8) + + // Assign high-order bytes to first 4 bytes of Long + let returnedLong = BitConverter.ToInt64(highBytes, 0) + + // Shift high-order bytes into position + let returnedLong = returnedLong <<< 32 + + // Or with low-order bytes + returnedLong ||| int64 fileTime.dwLowDateTime + +let [] OPEN_EXISTING = 3 +let [] INVALID_HANDLE_VALUE = -1 + +[] +extern int CreateFile(string lpFileName, + int dwDesiredAccess, + int dwShareMode, + int lpSecurityAttributes, + int dwCreationDisposition, + int dwFlagsAndAttributes, + int hTemplateFile) + +[] +extern bool GetFileTime(int hFile, + nativeint lpCreationTime, + nativeint lpLastAccessTime, + nativeint lpLastWriteTime) + +[] +extern bool CloseHandle(int hFile) + + +// Open file %windir%\write.exe +let winDir = + let winDir = Environment.SystemDirectory + let winDir = + if winDir.EndsWith(string Path.DirectorySeparatorChar) then + winDir + else + winDir + string Path.DirectorySeparatorChar + winDir + "write.exe" + +// Get file time using Windows API +// Open file +let hFile = CreateFile(winDir, 0, 0, 0, OPEN_EXISTING, 0, 0) + +if hFile = INVALID_HANDLE_VALUE then + printfn $"Unable to access {winDir}." +else + let mutable creationTime = Unchecked.defaultof + let mutable accessTime = Unchecked.defaultof + let mutable writeTime = Unchecked.defaultof + + if GetFileTime(hFile, NativePtr.toNativeInt &&creationTime, NativePtr.toNativeInt &&accessTime, NativePtr.toNativeInt &&writeTime) then + let fileCreationTime = FileTime.ToLong creationTime + let fileAccessTime = FileTime.ToLong accessTime + let fileWriteTime = FileTime.ToLong writeTime + + printfn $"File {winDir} Retrieved Using the Windows API:" + printfn $" Created: {DateTimeOffset.FromFileTime fileCreationTime |> string:d}" + printfn $" Last Access: {DateTimeOffset.FromFileTime fileAccessTime |> string:d}" + printfn $" Last Write: {DateTimeOffset.FromFileTime fileWriteTime |> string:d}\n" + +// Get date and time, convert to file time, then convert back +let fileInfo = FileInfo winDir + +// Get dates and times of file creation, last access, and last write +let infoCreationTime = fileInfo.CreationTime +let infoAccessTime = fileInfo.LastAccessTime +let infoWriteTime = fileInfo.LastWriteTime + +// Convert values to file times +let ftCreationTime = infoCreationTime.ToFileTime() +let ftAccessTime = infoAccessTime.ToFileTime() +let ftWriteTime = infoWriteTime.ToFileTime() + +// Convert file times back to DateTimeOffset values +printfn $"File {winDir} Retrieved Using a FileInfo Object:" +printfn $" Created: {DateTimeOffset.FromFileTime ftCreationTime |> string:d}" +printfn $" Last Access: {DateTimeOffset.FromFileTime ftAccessTime |> string:d}" +printfn $" Last Write: {DateTimeOffset.FromFileTime ftWriteTime |> string:d}" + + +// The example produces the following output: +// File C:\WINDOWS\system32\write.exe Retrieved Using the Windows API: +// Created: 10/13/2005 5:26:59 PM -07:00 +// Last Access: 3/20/2007 2:07:00 AM -07:00 +// Last Write: 8/4/2004 5:00:00 AM -07:00 +// +// File C:\WINDOWS\system32\write.exe Retrieved Using a FileInfo Object: +// Created: 10/13/2005 5:26:59 PM -07:00 +// Last Access: 3/20/2007 2:07:00 AM -07:00 +// Last Write: 8/4/2004 5:00:00 AM -07:00 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/fs.fsproj new file mode 100644 index 00000000000..6bf59a35e6e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs new file mode 100644 index 00000000000..739f8a29757 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs @@ -0,0 +1,294 @@ +module Methods + +open System + +let showSchedule () = + // + let takeOff = DateTimeOffset(2007, 6, 1, 7, 55, 0, TimeSpan(-5, 0, 0)) + let mutable currentTime = takeOff + let flightTimes = [| TimeSpan(2, 25, 0); TimeSpan(1, 48, 0) |] + printfn $"Takeoff is scheduled for {takeOff:d} at {takeOff:T}." + + for i = 0 to flightTimes.Length - 1 do + currentTime <- currentTime.Add flightTimes[i] + printfn $"Destination #{i + 1} at {currentTime}." + // + +let showStartOfWorkWeek () = + // + let workDay = DateTimeOffset(2008, 3, 1, 9, 0, 0, DateTimeOffset.Now.Offset) + let month = workDay.Month + + // Start with the first Monday of the month + let mutable workDay = + match workDay.DayOfWeek with + | DayOfWeek.Monday -> + workDay + | DayOfWeek.Sunday -> + workDay.AddDays 1 + | _ -> + workDay.AddDays(8. - float workDay.DayOfWeek) + + printfn $"Beginning of Work Week In {workDay:MMMM} {workDay:yyyy}:" + + // Add one week to the current date + while workDay.Month = month do + printfn $" {workDay:dddd}, {workDay:MMMM}{workDay: d}" + workDay <- workDay.AddDays 7 + + // The example produces the following output: + // Beginning of Work Week In March 2008: + // Monday, March 3 + // Monday, March 10 + // Monday, March 17 + // Monday, March 24 + // Monday, March 31 + // + +let showShiftStartTimes () = + // + let shiftLength = 8 + + let startTime = DateTimeOffset(2007, 8, 6, 0, 0, 0, DateTimeOffset.Now.Offset) + let mutable startOfShift = startTime.AddHours shiftLength + + printfn $"Shifts for the week of {startOfShift:D}" + while startOfShift.DayOfWeek <> DayOfWeek.Saturday && + startOfShift.DayOfWeek <> DayOfWeek.Sunday do + // Exclude third shift + if startOfShift.Hour > 6 then + printfn $" {startOfShift:d} at {startOfShift:T}" + + startOfShift <- startOfShift.AddHours shiftLength + + // The example produces the following output: + // + // Shifts for the week of Monday, August 06, 2007 + // 8/6/2007 at 8:00:00 AM + // 8/6/2007 at 4:00:00 PM + // 8/7/2007 at 8:00:00 AM + // 8/7/2007 at 4:00:00 PM + // 8/8/2007 at 8:00:00 AM + // 8/8/2007 at 4:00:00 PM + // 8/9/2007 at 8:00:00 AM + // 8/9/2007 at 4:00:00 PM + // 8/10/2007 at 8:00:00 AM + // 8/10/2007 at 4:00:00 PM + // + +let showQuarters () = + // + let mutable quarterDate = DateTimeOffset(2007, 1, 1, 0, 0, 0, DateTimeOffset.Now.Offset) + for i = 1 to 4 do + printfn $"""Quarter {i}: {quarterDate.ToString "MMMM d"}""" + quarterDate <- quarterDate.AddMonths 3 + + // This example produces the following output: + // Quarter 1: January 1 + // Quarter 2: April 1 + // Quarter 3: July 1 + // Quarter 4: October 1 + // + + +let showLegalLicenseAge () = + // + let minimumAge = 16 + let dateToday = DateTimeOffset.Now + let latestBirthday = dateToday.AddYears(-1 * minimumAge) + printfn $"To possess a driver's license, you must have been born on or before {latestBirthday:d}." + // + +let compareForEquality1 () = + // + let firstTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-7, 0, 0)) + + let secondTime = firstTime + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-6, 0, 0)) + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = DateTimeOffset(2007, 9, 1, 8, 45, 0, TimeSpan(-5, 0, 0)) + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + // The example displays the following output to the console: + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 6:45:00 AM -07:00: True + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 6:45:00 AM -06:00: False + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 8:45:00 AM -05:00: True + // + +// +let compareForEquality2 () = + let firstTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-7, 0, 0)) + + let secondTime: obj = firstTime + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-6, 0, 0)) + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = DateTimeOffset(2007, 9, 1, 8, 45, 0, TimeSpan(-5, 0, 0)) + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = null + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + let secondTime = DateTime(2007, 9, 1, 6, 45, 00) + printfn $"{firstTime} = {secondTime}: {firstTime.Equals secondTime}" + + // The example displays the following output to the console: + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 6:45:00 AM -07:00: True + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 6:45:00 AM -06:00: False + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 8:45:00 AM -05:00: True + // 9/1/2007 6:45:00 AM -07:00 = : False + // 9/1/2007 6:45:00 AM -07:00 = 9/1/2007 6:45:00 AM: False + // + +let compareForEquality3 () = + // + let firstTime = DateTimeOffset(2007, 11, 15, 11, 35, 00, DateTimeOffset.Now.Offset) + let secondTime = firstTime + printfn $"{firstTime} = {secondTime}: {DateTimeOffset.Equals(firstTime, secondTime)}" + + // The value of firstTime remains unchanged + let secondTime = DateTimeOffset(firstTime.DateTime, TimeSpan.FromHours(firstTime.Offset.Hours + 1 |> float)) + printfn $"{firstTime} = {secondTime}: {DateTimeOffset.Equals(firstTime, secondTime)}" + + // value of firstTime remains unchanged + let secondTime = DateTimeOffset(firstTime.DateTime + TimeSpan.FromHours 1, TimeSpan.FromHours(firstTime.Offset.Hours + 1 |> float)) + printfn $"{firstTime} = {secondTime}: {DateTimeOffset.Equals(firstTime, secondTime)}" + + // The example produces the following output: + // 11/15/2007 11:35:00 AM -07:00 = 11/15/2007 11:35:00 AM -07:00: True + // 11/15/2007 11:35:00 AM -07:00 = 11/15/2007 11:35:00 AM -06:00: False + // 11/15/2007 11:35:00 AM -07:00 = 11/15/2007 12:35:00 PM -06:00: True + // + +let compareExactly () = + // + let instanceTime = DateTimeOffset(2007, 10, 31, 0, 0, 0, DateTimeOffset.Now.Offset) + + let otherTime = instanceTime + printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}" + + let otherTime = DateTimeOffset(instanceTime.DateTime, TimeSpan.FromHours(instanceTime.Offset.Hours + 1 |> float)) + printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}" + + let otherTime = DateTimeOffset(instanceTime.DateTime + TimeSpan.FromHours 1, TimeSpan.FromHours(instanceTime.Offset.Hours + 1 |> float)) + printfn $"{instanceTime} = {otherTime}: {instanceTime.EqualsExact otherTime}" + + // The example produces the following output: + // 10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -07:00: True + // 10/31/2007 12:00:00 AM -07:00 = 10/31/2007 12:00:00 AM -06:00: False + // 10/31/2007 12:00:00 AM -07:00 = 10/31/2007 1:00:00 AM -06:00: False + // + +let subtract1 () = + // + let firstDate = DateTimeOffset(2018, 10, 25, 18, 0, 0, TimeSpan(-7, 0, 0)) + let secondDate = DateTimeOffset(2018, 10, 25, 18, 0, 0, TimeSpan(-5, 0, 0)) + let thirdDate = DateTimeOffset(2018, 9, 28, 9, 0, 0, TimeSpan(-7, 0, 0)) + + let difference = firstDate.Subtract secondDate + printfn $"({firstDate}) - ({secondDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}" + + let difference = firstDate.Subtract thirdDate + printfn $"({firstDate}) - ({thirdDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}" + + // The example produces the following output: + // (10/25/2018 6:00:00 PM -07:00) - (10/25/2018 6:00:00 PM -05:00): 0 days, 2:00 + // (10/25/2018 6:00:00 PM -07:00) - (9/28/2018 9:00:00 AM -07:00): 27 days, 9:00 + // + +let subtract2 () = + // + let offsetDate = DateTimeOffset(2007, 12, 3, 11, 30, 0, TimeSpan(-8, 0, 0)) + let duration = TimeSpan(7, 18, 0, 0) + printfn $"{offsetDate.Subtract duration}" // Displays 11/25/2007 5:30:00 PM -08:00 + // + +let convertToLocal () = + // + // Local time changes on 3/11/2007 at 2:00 AM + let originalTime = DateTimeOffset(2007, 3, 11, 3, 0, 0, TimeSpan(-6, 0, 0)) + let localTime = originalTime.ToLocalTime() + printfn $"Converted {originalTime} to {localTime}." + + let originalTime = DateTimeOffset(2007, 3, 11, 4, 0, 0, TimeSpan(-6, 0, 0)) + let localTime = originalTime.ToLocalTime() + printfn $"Converted {originalTime} to {localTime}." + + // Define a summer UTC time + let originalTime = DateTimeOffset(2007, 6, 15, 8, 0, 0, TimeSpan.Zero) + let localTime = originalTime.ToLocalTime() + printfn $"Converted {originalTime} to {localTime}." + + // Define a winter time + let originalTime = DateTimeOffset(2007, 11, 30, 14, 0, 0, TimeSpan(3, 0, 0)) + let localTime = originalTime.ToLocalTime() + printfn $"Converted {originalTime} to {localTime}." + + // The example produces the following output: + // Converted 3/11/2007 3:00:00 AM -06:00 to 3/11/2007 1:00:00 AM -08:00. + // Converted 3/11/2007 4:00:00 AM -06:00 to 3/11/2007 3:00:00 AM -07:00. + // Converted 6/15/2007 8:00:00 AM +00:00 to 6/15/2007 1:00:00 AM -07:00. + // Converted 11/30/2007 2:00:00 PM +03:00 to 11/30/2007 3:00:00 AM -08:00. + // + +let convertToUniversal () = + // + // Define local time in local time zone + let localTime = DateTimeOffset(DateTime(2007, 6, 15, 12, 0, 0)) + printfn $"Local time: {localTime}\n" + + // Convert local time to offset 0 and assign to otherTime + let otherTime = localTime.ToOffset TimeSpan.Zero + printfn $"Other time: {otherTime}" + printfn $"{localTime} = {otherTime}: {localTime.Equals otherTime}" + printfn $"{localTime} exactly equals {otherTime}: {localTime.EqualsExact otherTime}\n" + + // Convert other time to UTC + let universalTime = localTime.ToUniversalTime() + printfn $"Universal time: {universalTime}" + printfn $"{otherTime} = {universalTime}: {universalTime.Equals otherTime}" + printfn $"{otherTime} exactly equals {universalTime}: {universalTime.EqualsExact otherTime}\n" + + // The example produces the following output to the console: + // Local time: 6/15/2007 12:00:00 PM -07:00 + // + // Other time: 6/15/2007 7:00:00 PM +00:00 + // 6/15/2007 12:00:00 PM -07:00 = 6/15/2007 7:00:00 PM +00:00: True + // 6/15/2007 12:00:00 PM -07:00 exactly equals 6/15/2007 7:00:00 PM +00:00: False + // + // Universal time: 6/15/2007 7:00:00 PM +00:00 + // 6/15/2007 7:00:00 PM +00:00 = 6/15/2007 7:00:00 PM +00:00: True + // 6/15/2007 7:00:00 PM +00:00 exactly equals 6/15/2007 7:00:00 PM +00:00: True + // + +showSchedule () +printfn $"----------" +showStartOfWorkWeek () +printfn $"----------" +showShiftStartTimes () +printfn $"----------" +showQuarters () +printfn $"----------" +showLegalLicenseAge () +printfn $"----------" +compareForEquality1 () +printfn $"----------" +compareForEquality2 () +printfn $"----------" +compareForEquality3 () +printfn $"----------" +compareExactly () +printfn $"----------" +subtract1 () +printfn $"----------" +subtract2 () +printfn $"----------" +convertToLocal () +printfn $"----------" +convertToUniversal () +printfn $"----------" \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs new file mode 100644 index 00000000000..06ef4e694bb --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs @@ -0,0 +1,26 @@ +module Methods2 + +// +open System + +type TimeComparison = + | Earlier = -1 + | Same = 0 + | Later = 1 + +let firstTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-7, 0, 0)) + +let secondTime = firstTime +printfn $"Comparing {firstTime} and {secondTime}: {DateTimeOffset.Compare(firstTime, secondTime) |> enum}" + +let thirdTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-6, 0, 0)) +printfn $"Comparing {firstTime} and {thirdTime}: {DateTimeOffset.Compare(firstTime, thirdTime) |> enum}" + +let fourthTime = DateTimeOffset(2007, 9, 1, 8, 45, 0, TimeSpan(-5, 0, 0)) +printfn $"Comparing {firstTime} and {fourthTime}: {DateTimeOffset.Compare(firstTime, fourthTime) |> enum}" + +// The example displays the following output to the console: +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -07:00: Same +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -06:00: Later +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 8:45:00 AM -05:00: Same +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs new file mode 100644 index 00000000000..f35e61e33d3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs @@ -0,0 +1,27 @@ +module Methods3 + +// +open System + +type TimeComparison = + | Earlier = -1 + | Same = 0 + | Later = 1 + +let firstTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-7, 0, 0)) + +let secondTime = firstTime +printfn $"Comparing {firstTime} and {secondTime}: {firstTime.CompareTo secondTime |> enum}" + +let thirdTime = DateTimeOffset(2007, 9, 1, 6, 45, 0, TimeSpan(-6, 0, 0)) +printfn $"Comparing {firstTime} and {thirdTime}: {firstTime.CompareTo thirdTime |> enum}" + +let fourthTime = new DateTimeOffset(2007, 9, 1, 8, 45, 0, + new TimeSpan(-5, 0, 0)) +printfn $"Comparing {firstTime} and {fourthTime}: {firstTime.CompareTo fourthTime |> enum}" + +// The example displays the following output to the console: +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -07:00: Same +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 6:45:00 AM -06:00: Later +// Comparing 9/1/2007 6:45:00 AM -07:00 and 9/1/2007 8:45:00 AM -05:00: Same +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/fs.fsproj new file mode 100644 index 00000000000..477361ca061 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/fs.fsproj @@ -0,0 +1,11 @@ + + + Exe + net6.0 + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs new file mode 100644 index 00000000000..0daaa4cce87 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs @@ -0,0 +1,185 @@ +open System + +let showAddition () = + // + let date1 = + DateTimeOffset(2008, 1, 1, 13, 32, 45, TimeSpan(-5, 0, 0)) + + let interval1 = TimeSpan(202, 3, 30, 0) + let interval2 = TimeSpan(5, 0, 0, 0) + + printfn $"{date1}" // Displays 1/1/2008 1:32:45 PM -05:00 + let date2 = date1 + interval1 + printfn $"{date2}" // Displays 7/21/2008 5:02:45 PM -05:00 + let date2 = date2 + interval2 + printfn $"{date2}" // Displays 7/26/2008 5:02:45 PM -05:00 + // + +let showEquality () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-6, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-6, 0, 0)) + + printfn $"{date1 = date2}" // Displays True + printfn $"{date1 = date3}" // Displays False + // + +let showGreaterThan () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-6, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-6, 0, 0)) + + printfn $"{date1 > date2}" // Displays False + printfn $"{date1 > date3}" // Displays True +// + +let showGreaterThanOrEqualTo () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-7, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-6, 0, 0)) + + let date4 = date1 + printfn $"{date1 >= date2}" // Displays False + printfn $"{date1 >= date3}" // Displays True + printfn $"{date1 >= date4}" // Displays True + // + +let showImplicitConversions () = + // + let timeWithOffset = DateTime(2008, 7, 3, 18, 45, 0) + printfn $"{timeWithOffset}" + + let timeWithOffset = DateTime.UtcNow + printfn $"{timeWithOffset}" + + let timeWithOffset = + DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Unspecified) + + printfn $"{timeWithOffset}" + + let timeWithOffset = + DateTime(2008, 7, 1, 2, 30, 0) + + TimeSpan(1, 0, 0, 0) + + printfn $"{timeWithOffset}" + + let timeWithOffset = DateTime(2008, 1, 1, 2, 30, 0) + printfn $"{timeWithOffset}" + + // The example produces the following output if run on 3/20/2007 + // at 6:25 PM on a computer in the U.S. Pacific Daylight Time zone: + // 7/3/2008 6:45:00 PM -07:00 + // 3/21/2007 1:25:52 AM +00:00 + // 3/20/2007 6:25:52 PM -07:00 + // 7/2/2008 2:30:00 AM -07:00 + // 1/1/2008 2:30:00 AM -08:00 + // + // The last example shows automatic adaption to the U.S. Pacific Time + // for winter dates. + // + +let showInequality () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-6, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-6, 0, 0)) + + printfn $"{date1 <> date2}" // Displays False + printfn $"{date1 <> date3}" // Displays True + // + +let showLessThan () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-6, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-8, 0, 0)) + + printfn $"{date1 < date2}" // Displays False + printfn $"{date1 < date3}" // Displays True + // + +let showLessThanOrEqualTo () = + // + let date1 = + DateTimeOffset(2007, 6, 3, 14, 45, 0, TimeSpan(-7, 0, 0)) + + let date2 = + DateTimeOffset(2007, 6, 3, 15, 45, 0, TimeSpan(-7, 0, 0)) + + let date3 = + DateTimeOffset(date1.DateTime, TimeSpan(-6, 0, 0)) + + let date4 = date1 + printfn $"{date1 <= date2}" // Displays True + printfn $"{date1 <= date3}" // Displays False + printfn $"{date1 <= date4}" // Displays True + // + +let showSubtraction1 () = + // + let firstDate = + DateTimeOffset(2008, 3, 25, 18, 0, 0, TimeSpan(-7, 0, 0)) + + let secondDate = + DateTimeOffset(2008, 3, 25, 18, 0, 0, TimeSpan(-5, 0, 0)) + + let thirdDate = + DateTimeOffset(2008, 2, 28, 9, 0, 0, TimeSpan(-7, 0, 0)) + + let difference = firstDate - secondDate + printfn $"({firstDate}) - ({secondDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}" + + let difference = firstDate - thirdDate + printfn $"({firstDate}) - ({secondDate}): {difference.Days} days, {difference.Hours}:{difference.Minutes:d2}" + // The example produces the following output: + // (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 0 days, 2:00 + // (3/25/2008 6:00:00 PM -07:00) - (3/25/2008 6:00:00 PM -05:00): 26 days, 9:00 + // + +let showSubtraction2 () = + // + let offsetDate = + DateTimeOffset(2007, 12, 3, 11, 30, 0, TimeSpan(-8, 0, 0)) + + let duration = TimeSpan(7, 18, 0, 0) + printfn $"{offsetDate - duration}" // Displays 11/25/2007 5:30:00 PM -08:00 + // + +showAddition () +showEquality () +showGreaterThan () +showGreaterThanOrEqualTo () +showImplicitConversions () +showInequality () +showLessThan () +showLessThanOrEqualTo () +showSubtraction1 () +showSubtraction2 () diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/fs.fsproj new file mode 100644 index 00000000000..311f4db7f3a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs new file mode 100644 index 00000000000..099b2641265 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs @@ -0,0 +1,67 @@ +open System +open System.Globalization + +let parseOverload1 () = + // + // String with date only + let dateString = "05/01/2008" + let offsetDate = DateTimeOffset.Parse dateString + printfn $"{offsetDate}" + + // String with time only + let dateString = "11:36 PM" + let offsetDate = DateTimeOffset.Parse dateString + printfn $"{offsetDate}" + + // String with date and offset + let dateString = "05/01/2008 +1:00" + let offsetDate = DateTimeOffset.Parse dateString + printfn $"{offsetDate}" + + // String with day abbreviation + let dateString = "Thu May 01, 2008" + let offsetDate = DateTimeOffset.Parse(dateString) + printfn $"{offsetDate}" + // + +let parseOverload2 () = + // + let fmt = CultureInfo("fr-fr").DateTimeFormat + let dateString = "03-12-07" + let offsetDate = DateTimeOffset.Parse(dateString, fmt) + printfn $"{dateString} returns {offsetDate}" + + let dateString = "15/09/07 08:45:00 +1:00" + let offsetDate = DateTimeOffset.Parse(dateString, fmt) + printfn $"{dateString} returns {offsetDate}" + + let dateString = "mar. 1 janvier 2008 1:00:00 +1:00" + let offsetDate = DateTimeOffset.Parse(dateString, fmt) + printfn $"{dateString} returns {offsetDate}" + + // The example displays the following output to the console: + // 03-12-07 returns 12/3/2007 12:00:00 AM -08:00 + // 15/09/07 08:45:00 +1:00 returns 9/15/2007 8:45:00 AM +01:00 + // mar. 1 janvier 2008 1:00:00 +1:00 returns 1/1/2008 1:00:00 AM +01:00 + // + +let parseOverload3 () = + // + let dateString = "05/01/2008 6:00:00" + // Assume time is local + let offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeLocal) + printfn $"{offsetDate}" // Displays 5/1/2008 6:00:00 AM -07:00 + + // Assume time is UTC + let offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AssumeUniversal) + printfn $"{offsetDate}" // Displays 5/1/2008 6:00:00 AM +00:00 + + // Parse and convert to UTC + let dateString = "05/01/2008 6:00:00AM +5:00" + let offsetDate = DateTimeOffset.Parse(dateString, null, DateTimeStyles.AdjustToUniversal) + printfn $"{offsetDate}" // Displays 5/1/2008 1:00:00 AM +00:00 + // + +parseOverload1 () +parseOverload2 () +parseOverload3 () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/fs.fsproj new file mode 100644 index 00000000000..49c822ced42 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs new file mode 100644 index 00000000000..5dda7986cd0 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs @@ -0,0 +1,169 @@ +open System +open System.Globalization +open System.IO + +let parseExact1 () = + // + let provider = CultureInfo.InvariantCulture + + // Parse date-only value with invariant culture. + let dateString = "06/15/2008" + let format = "d" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + // Parse date-only value without leading zero in month using "d" format. + // Should throw a FormatException because standard short date pattern of + // invariant culture requires two-digit month. + let dateString = "6/15/2008" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + // Parse date and time with custom specifier. + let dateString = "Sun 15 Jun 2008 8:30 AM -06:00" + let format = "ddd dd MMM yyyy h:mm tt zzz" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + // Parse date and time with offset without offset//s minutes. + // Should throw a FormatException because "zzz" specifier requires leading + // zero in hours. + let dateString = "Sun 15 Jun 2008 8:30 AM -06" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + // The example displays the following output: + // 06/15/2008 converts to 6/15/2008 12:00:00 AM -07:00. + // 6/15/2008 is not in the correct format. + // Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 8:30:00 AM -06:00. + // Sun 15 Jun 2008 8:30 AM -06 is not in the correct format. + // + +let parseExact2 () = + // + let provider = CultureInfo.InvariantCulture + + // Parse date-only value with invariant culture and assume time is UTC. + let dateString = "06/15/2008" + let format = "d" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AssumeUniversal) + printfn $"'{dateString}' converts to {result}." + with :? FormatException -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date-only value with leading white space. + // Should throw a FormatException because only trailing white space is + // specified in method call. + let dateString = " 06/15/2008" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AllowTrailingWhite) + printfn $"'{dateString}' converts to {result}." + with :? FormatException -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date and time value, and allow all white space. + let dateString = " 06/15/ 2008 15:15 -05:00" + let format = "MM/dd/yyyy H:mm zzz" + try + let result = DateTimeOffset.ParseExact(dateString, format, provider, DateTimeStyles.AllowWhiteSpaces) + printfn $"'{dateString}' converts to {result}." + with :? FormatException -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date and time and convert to UTC. + let dateString = " 06/15/2008 15:15:30 -05:00" + let format = "MM/dd/yyyy H:mm:ss zzz" + try + let result = + DateTimeOffset.ParseExact(dateString, format, provider, + DateTimeStyles.AllowWhiteSpaces ||| + DateTimeStyles.AdjustToUniversal) + printfn $"'{dateString}' converts to {result}." + with :? FormatException -> + printfn $"'{dateString}' is not in the correct format." + + // The example displays the following output: + // '06/15/2008' converts to 6/15/2008 12:00:00 AM +00:00. + // ' 06/15/2008' is not in the correct format. + // ' 06/15/ 2008 15:15 -05:00' converts to 6/15/2008 3:15:00 PM -05:00. + // ' 06/15/2008 15:15:30 -05:00' converts to 6/15/2008 8:15:30 PM +00:00. + // + +let parseExact3 () = + // + let input = String.Empty + let formats = + [| @"@M/dd/yyyy HH:m zzz"; @"MM/dd/yyyy HH:m zzz"; + @"M/d/yyyy HH:m zzz"; @"MM/d/yyyy HH:m zzz" + @"M/dd/yy HH:m zzz"; @"MM/dd/yy HH:m zzz" + @"M/d/yy HH:m zzz"; @"MM/d/yy HH:m zzz" + @"M/dd/yyyy H:m zzz"; @"MM/dd/yyyy H:m zzz" + @"M/d/yyyy H:m zzz"; @"MM/d/yyyy H:m zzz" + @"M/dd/yy H:m zzz"; @"MM/dd/yy H:m zzz" + @"M/d/yy H:m zzz"; @"MM/d/yy H:m zzz" + @"M/dd/yyyy HH:mm zzz"; @"MM/dd/yyyy HH:mm zzz" + @"M/d/yyyy HH:mm zzz"; @"MM/d/yyyy HH:mm zzz" + @"M/dd/yy HH:mm zzz"; @"MM/dd/yy HH:mm zzz" + @"M/d/yy HH:mm zzz"; @"MM/d/yy HH:mm zzz" + @"M/dd/yyyy H:mm zzz"; @"MM/dd/yyyy H:mm zzz" + @"M/d/yyyy H:mm zzz"; @"MM/d/yyyy H:mm zzz" + @"M/dd/yy H:mm zzz"; @"MM/dd/yy H:mm zzz" + @"M/d/yy H:mm zzz"; @"MM/d/yy H:mm zzz" |] + let provider = CultureInfo.InvariantCulture.DateTimeFormat + + let mutable result = None + let mutable tries = 0 + while tries < 3 && result.IsNone do + printfn "Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM)," + printf "Then press Enter: " + let input = stdin.ReadLine() + printfn "" + try + result <- + DateTimeOffset.ParseExact(input, formats, provider, DateTimeStyles.AllowWhiteSpaces) + |> Some + with :? FormatException -> + printfn $"Unable to parse {input}." + tries <- tries + 1 + + match result with + | Some result -> + printfn $"{input} was converted to {result}" + | None -> + printfn $"Exiting application without parsing {input}" + + // Some successful sample interactions with the user might appear as follows: + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/08/2007 6:54 -6:00 + // + // 12/08/2007 6:54 -6:00 was converted to 12/8/2007 6:54:00 AM -06:00 + // + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/8/2007 06:54 -06:00 + // + // 12/8/2007 06:54 -06:00 was converted to 12/8/2007 6:54:00 AM -06:00 + // + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/5/07 6:54 -6:00 + // + // 12/5/07 6:54 -6:00 was converted to 12/5/2007 6:54:00 AM -06:00 + // + +parseExact1 () +printfn "" +parseExact2 () +printfn "" +parseExact3 () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/fs.fsproj new file mode 100644 index 00000000000..327649eab5c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs new file mode 100644 index 00000000000..df5a5c7ec8d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs @@ -0,0 +1,343 @@ +open System +open System.Globalization + +let showDateFormats () = + // + // Illustrate Date property and date formatting + let thisDate = DateTimeOffset(2008, 3, 17, 1, 32, 0, TimeSpan(-5, 0, 0)) + + // Display date only using "D" format specifier + // For en-us culture, displays: + // 'D' format specifier: Monday, March 17, 2008 + let fmt = "D" + printfn $"'{fmt}' format specifier: {thisDate.Date.ToString fmt}" + + // Display date only using "d" format specifier + // For en-us culture, displays: + // 'd' format specifier: 3/17/2008 + let fmt = "d" + printfn $"'{fmt}' format specifier: {thisDate.Date.ToString fmt}" + + // Display date only using "Y" (or "y") format specifier + // For en-us culture, displays: + // 'Y' format specifier: March, 2008 + let fmt = "Y" + printfn $"'{fmt}' format specifier: {thisDate.Date.ToString fmt}" + + // Display date only using custom format specifier + // For en-us culture, displays: + // 'dd MMM yyyy' format specifier: 17 Mar 2008 + let fmt = "dd MMM yyyy" + printfn $"'{fmt}' format specifier: {thisDate.Date.ToString fmt}" + // + +let convertToDateTime () = + // + let offsetDate = DateTimeOffset.Now + let regularDate = offsetDate.DateTime + printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}." + + let offsetDate = DateTimeOffset.UtcNow + let regularDate = offsetDate.DateTime + printfn $"{offsetDate} converts to {regularDate}, Kind {regularDate.Kind}." + + // If run on 3/6/2007 at 17:11, produces the following output: + // + // 3/6/2007 5:11:22 PM -08:00 converts to 3/6/2007 5:11:22 PM, Kind Unspecified. + // 3/7/2007 1:11:22 AM +00:00 converts to 3/7/2007 1:11:22 AM, Kind Unspecified. + // + +let showFirstOfMonth () = + // + let mutable startOfMonth = DateTimeOffset(2008, 1, 1, 0, 0, 0, DateTimeOffset.Now.Offset) + let year = startOfMonth.Year + + while startOfMonth.Year = year do + printfn $"""{startOfMonth.ToString "MMM d, yyyy"} is a {startOfMonth.DayOfWeek}.""" + startOfMonth <- startOfMonth.AddMonths 1 + + // This example writes the following output to the console: + // Jan 1, 2008 is a Tuesday. + // Feb 1, 2008 is a Friday. + // Mar 1, 2008 is a Saturday. + // Apr 1, 2008 is a Tuesday. + // May 1, 2008 is a Thursday. + // Jun 1, 2008 is a Sunday. + // Jul 1, 2008 is a Tuesday. + // Aug 1, 2008 is a Friday. + // Sep 1, 2008 is a Monday. + // Oct 1, 2008 is a Wednesday. + // Nov 1, 2008 is a Saturday. + // Dec 1, 2008 is a Monday. + // + + // + let displayDate = DateTimeOffset(2008, 1, 1, 13, 18, 00, DateTimeOffset.Now.Offset) + printfn $"{displayDate:D}" // Output: Tuesday, January 01, 2008 + printfn $"{displayDate:d} is a {displayDate:dddd}." // Output: 1/1/2008 is a Tuesday. + // + + // + let thisDate = DateTimeOffset(2007, 6, 1, 6, 15, 0, DateTimeOffset.Now.Offset) + let weekdayName = thisDate.ToString("dddd", CultureInfo "fr-fr") + printfn $"{weekdayName}" // Displays vendredi + // + +let showHour () = + // + let theTime = DateTimeOffset(2008, 3, 1, 14, 15, 00, DateTimeOffset.Now.Offset) + printfn $"The hour component of {theTime} is {theTime.Hour}." + + printfn $"""The hour component of {theTime} is{theTime.ToString " H"}.""" + + printfn $"The hour component of {theTime} is {theTime:HH}." + + // The example produces the following output: + // The hour component of 3/1/2008 2:15:00 PM -08:00 is 14. + // The hour component of 3/1/2008 2:15:00 PM -08:00 is 14. + // The hour component of 3/1/2008 2:15:00 PM -08:00 is 14. + // + +let convertToLocalTime () = + // + // Current time + let dto = DateTimeOffset.Now + printfn $"{dto.LocalDateTime}" + // UTC time + let dto = DateTimeOffset.UtcNow + printfn $"{dto.LocalDateTime}" + + // Transition to DST in local time zone occurs on 3/11/2007 at 2:00 AM + let dto = DateTimeOffset(2007, 3, 11, 3, 30, 0, TimeSpan(-7, 0, 0)) + printfn $"{dto.LocalDateTime}" + let dto = DateTimeOffset(2007, 3, 11, 2, 30, 0, TimeSpan(-7, 0, 0)) + printfn $"{dto.LocalDateTime}" + // Invalid time in local time zone + let dto = DateTimeOffset(2007, 3, 11, 2, 30, 0, TimeSpan(-8, 0, 0)) + printfn $"{TimeZoneInfo.Local.IsInvalidTime dto.DateTime}" + printfn $"{dto.LocalDateTime}" + + // Transition from DST in local time zone occurs on 11/4/07 at 2:00 AM + // This is an ambiguous time + let dto = DateTimeOffset(2007, 11, 4, 1, 30, 0, TimeSpan(-7, 0, 0)) + printfn $"{TimeZoneInfo.Local.IsAmbiguousTime dto}" + printfn $"{dto.LocalDateTime}" + let dto = DateTimeOffset(2007, 11, 4, 2, 30, 0, TimeSpan(-7, 0, 0)) + printfn $"{TimeZoneInfo.Local.IsAmbiguousTime dto}" + printfn $"{dto.LocalDateTime}" + // This is also an ambiguous time + let dto = DateTimeOffset(2007, 11, 4, 1, 30, 0, TimeSpan(-8, 0, 0)) + printfn $"{TimeZoneInfo.Local.IsAmbiguousTime dto}" + printfn $"{dto.LocalDateTime}" + + // If run on 3/8/2007 at 4:56 PM, the code produces the following + // output: + // 3/8/2007 4:56:03 PM + // 3/8/2007 4:56:03 PM + // 3/11/2007 3:30:00 AM + // 3/11/2007 1:30:00 AM + // True + // 3/11/2007 3:30:00 AM + // True + // 11/4/2007 1:30:00 AM + // 11/4/2007 1:30:00 AM + // True + // 11/4/2007 1:30:00 AM + // + +let showMinute () = + // + let theTime = DateTimeOffset(2008, 5, 1, 10, 3, 0, DateTimeOffset.Now.Offset) + printfn $"The minute component of {theTime} is {theTime.Minute}." + + printfn $"""The minute component of {theTime} is{theTime.ToString " m"}.""" + + printfn $"The minute component of {theTime} is {theTime:mm}." + + // The example produces the following output: + // The minute component of 5/1/2008 10:03:00 AM -08:00 is 3. + // The minute component of 5/1/2008 10:03:00 AM -08:00 is 3. + // The minute component of 5/1/2008 10:03:00 AM -08:00 is 03. + // + +let showMonth () = + // + let theTime = DateTimeOffset(2008, 9, 7, 11, 25, 0, DateTimeOffset.Now.Offset) + printfn $"The month component of {theTime} is {theTime.Month}." + + printfn $"""The month component of {theTime} is{theTime.ToString " M"}.""" + + printfn $"""The month component of {theTime} is {theTime.ToString "MM"}.""" + + // The example produces the following output: + // The month component of 9/7/2008 11:25:00 AM -08:00 is 9. + // The month component of 9/7/2008 11:25:00 AM -08:00 is 9. + // The month component of 9/7/2008 11:25:00 AM -08:00 is 09. + // + +let showDay () = + // + let theTime = DateTimeOffset(2007, 5, 1, 16, 35, 0, DateTimeOffset.Now.Offset) + printfn $"The day component of {theTime} is {theTime.Day}." + + printfn $"""The day component of {theTime} is{theTime.ToString " d"}.""" + + printfn $"The day component of {theTime} is {theTime:dd}." + + // The example produces the following output: + // The day component of 5/1/2007 4:35:00 PM -08:00 is 1. + // The day component of 5/1/2007 4:35:00 PM -08:00 is 1. + // The day component of 5/1/2007 4:35:00 PM -08:00 is 01. + // + +let showResolution () = + // + let mutable ms = 0 + for _ = 0 to 99 do + let dto = DateTimeOffset.Now + if dto.Millisecond <> ms then + ms <- dto.Millisecond + printfn $"""{dto.ToString "M/d/yyyy h:mm:ss"}:{ms:d3} ms. {dto:zzz}""" + // + +let showMilliseconds () = + // + let date1 = DateTimeOffset(2008, 3, 5, 5, 45, 35, 649, TimeSpan(-7, 0, 0)) + printfn $"""Milliseconds value of {date1.ToString "MM/dd/yyyy hh:mm:ss.fff"} is {date1.Millisecond}.""" + + // The example produces the following output: + // + // Milliseconds value of 03/05/2008 05:45:35.649 is 649. + // + +let showLocalOffset () = + // + let localTime = DateTimeOffset.Now + printfn $"""The local time zone is {abs localTime.Offset.Hours} hours and {localTime.Offset.Minutes} minutes {if localTime.Offset.Hours < 0 then "earlier" else "later"} than UTC.""" + + // The example displays output similar to the following for a system in the + // U.S. Pacific Standard Time zone: + // The local time zone is 8 hours and 0 minutes earlier than UTC. + // + +let showSeconds () = + // + let theTime = DateTimeOffset(2008, 6, 12, 21, 16, 32, DateTimeOffset.Now.Offset) + printfn $"The second component of {theTime} is {theTime.Second}." + + printfn $"""The second component of {theTime} is{theTime.ToString " s"}.""" + + printfn $"The second component of {theTime} is {theTime:ss}." + + // The example produces the following output: + // The second component of 6/12/2008 9:16:32 PM -07:00 is 32. + // The second component of 6/12/2008 9:16:32 PM -07:00 is 32. + // The second component of 6/12/2008 9:16:32 PM -07:00 is 32. + // + +let illustrateTicks () = + // + // Attempt to initialize date to number of ticks + // in July 1, 2008 1:23:07. + // + // There are 10,000,000 100-nanosecond intervals in a second + let NSPerSecond = 10000000L + let ticks = 7L * NSPerSecond // Ticks in a 7 seconds + let ticks = ticks + 23L * 60L * NSPerSecond // Ticks in 23 minutes + let ticks = ticks + 1L * 60L * 60L * NSPerSecond // Ticks in 1 hour + let ticks = ticks + 60L * 60L * 24L * NSPerSecond // Ticks in 1 day + let ticks = ticks + 181L * 60L * 60L * 24L * NSPerSecond // Ticks in 6 months + let ticks = ticks + 2007L * 60L * 60L * 24L * 365L * NSPerSecond // Ticks in 2007 years + let ticks = ticks + 486L * 60L * 60L * 24L * NSPerSecond // Adjustment for leap years + let dto = DateTimeOffset(ticks, DateTimeOffset.Now.Offset) + printfn $"There are {ticks:n0} ticks in {dto}." + + // The example displays the following output: + // There are 633,504,721,870,000,000 ticks in 7/1/2008 1:23:07 AM -08:00. + // + +let showTime () = + // + let currentDate = DateTimeOffset(2008, 5, 10, 5, 32, 16, DateTimeOffset.Now.Offset) + let currentTime = currentDate.TimeOfDay + printfn $"The current time is {currentTime}." + // The example produces the following output: + // The current time is 05:32:16. + // + +let convertToUtc() = + // + let offsetTime = DateTimeOffset(2007, 11, 25, 11, 14, 00, TimeSpan(3, 0, 0)) + printfn $"{offsetTime} is equivalent to {offsetTime.UtcDateTime} {offsetTime.UtcDateTime.Kind}" + // The example displays the following output: + // 11/25/2007 11:14:00 AM +03:00 is equivalent to 11/25/2007 8:14:00 AM Utc + // + +let compareUtcAndLocal () = + // + let localTime = DateTimeOffset.Now + let utcTime = DateTimeOffset.UtcNow + + printfn $"Local Time: {localTime:T}" + printfn $"Difference from UTC: {localTime.Offset}" + printfn $"UTC: {utcTime:T}" + + // If run on a particular date at 1:19 PM, the example produces + // the following output: + // Local Time: 1:19:43 PM + // Difference from UTC: -07:00:00 + // UTC: 8:19:43 PM + // + +let showYear () = + // + let theTime = DateTimeOffset(2008, 2, 17, 9, 0, 0, DateTimeOffset.Now.Offset) + printfn $"The year component of {theTime} is {theTime.Year}." + + printfn $"""The year component of {theTime} is{theTime.ToString " y"}.""" + + printfn $"The year component of {theTime} is {theTime:yy}." + + printfn $"The year component of {theTime} is {theTime:yyyy}." + + // The example produces the following output: + // The year component of 2/17/2008 9:00:00 AM -07:00 is 2008. + // The year component of 2/17/2008 9:00:00 AM -07:00 is 8. + // The year component of 2/17/2008 9:00:00 AM -07:00 is 08. + // The year component of 2/17/2008 9:00:00 AM -07:00 is 2008. + // + +showDateFormats () +printfn "----------" +convertToDateTime () +printfn "----------" +showFirstOfMonth () +printfn "----------" +showHour () +printfn "----------" +convertToLocalTime () +printfn "----------" +showMinute () +printfn "----------" +showMonth () +printfn "----------" +showDay () +printfn "----------" +showResolution () +printfn "----------" +showMilliseconds () +printfn "----------" +showLocalOffset () +printfn "----------" +showSeconds () +printfn "----------" +illustrateTicks () +printfn "----------" +showTime () +printfn "----------" +convertToUtc () +printfn "----------" +compareUtcAndLocal () +printfn "----------" +showYear () +printfn "----------" \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/fs.fsproj new file mode 100644 index 00000000000..426c7e2caa6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs new file mode 100644 index 00000000000..c66654b1ab1 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs @@ -0,0 +1,50 @@ +open System + +let first = DateTimeOffset() +let second = DateTimeOffset() +let this = DateTimeOffset() +let other = DateTimeOffset() +let right = DateTimeOffset() +let left = DateTimeOffset() +let obj = obj() + +// +DateTime.Compare(first.UtcDateTime, second.UtcDateTime) +// +|> ignore + +// +this.UtcDateTime = other.UtcDateTime +// +|> ignore + +// +this.UtcDateTime = (obj :?> DateTimeOffset).UtcDateTime +// +|> ignore + +// +first.UtcDateTime = second.UtcDateTime +// +|> ignore + +// +left.UtcDateTime > right.UtcDateTime +// +|> ignore +// +left.UtcDateTime >= right.UtcDateTime +// +|> ignore +// +left.UtcDateTime <> right.UtcDateTime +// +|> ignore +// +left.UtcDateTime < right.UtcDateTime +// +|> ignore +// +left.UtcDateTime <= right.UtcDateTime +// +|> ignore \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/fs.fsproj new file mode 100644 index 00000000000..9739affa8ff --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs new file mode 100644 index 00000000000..e6b4a621d83 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs @@ -0,0 +1,47 @@ +// +open System + +let sourceTime = DateTimeOffset(2007, 9, 1, 9, 30, 0, TimeSpan(-5, 0, 0)) + +let showDateAndTimeInfo newTime = + printfn $"{sourceTime} converts to {newTime}" + printfn $"{sourceTime} and {newTime} are equal: {sourceTime.Equals newTime}" + printfn $"{sourceTime} and {newTime} are identical: {sourceTime.EqualsExact newTime}\n" + +[] +let main _ = + // Convert to same time (return sourceTime unchanged) + let targetTime = sourceTime.ToOffset(TimeSpan(-5, 0, 0)) + showDateAndTimeInfo targetTime + + // Convert to UTC (0 offset) + let targetTime = sourceTime.ToOffset TimeSpan.Zero + showDateAndTimeInfo targetTime + + // Convert to 8 hours behind UTC + let targetTime = sourceTime.ToOffset(TimeSpan(-8, 0, 0)) + showDateAndTimeInfo targetTime + + // Convert to 3 hours ahead of UTC + let targetTime = sourceTime.ToOffset(TimeSpan(3, 0, 0)) + showDateAndTimeInfo targetTime + + 0 + +// The example displays the following output: +// 9/1/2007 9:30:00 AM -05:00 converts to 9/1/2007 9:30:00 AM -05:00 +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 9:30:00 AM -05:00 are equal: True +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 9:30:00 AM -05:00 are identical: True +// +// 9/1/2007 9:30:00 AM -05:00 converts to 9/1/2007 2:30:00 PM +00:00 +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 2:30:00 PM +00:00 are equal: True +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 2:30:00 PM +00:00 are identical: False +// +// 9/1/2007 9:30:00 AM -05:00 converts to 9/1/2007 6:30:00 AM -08:00 +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 6:30:00 AM -08:00 are equal: True +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 6:30:00 AM -08:00 are identical: False +// +// 9/1/2007 9:30:00 AM -05:00 converts to 9/1/2007 5:30:00 PM +03:00 +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 5:30:00 PM +03:00 are equal: True +// 9/1/2007 9:30:00 AM -05:00 and 9/1/2007 5:30:00 PM +03:00 are identical: False +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/fs.fsproj new file mode 100644 index 00000000000..49b286bc279 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs new file mode 100644 index 00000000000..0c08a589339 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs @@ -0,0 +1,135 @@ +open System +open System.Globalization + +let toString1 () = + // + // Show output for UTC time + let thisDate = DateTimeOffset.UtcNow + printfn $"{thisDate.ToString()}" // Displays 3/28/2007 7:13:50 PM +00:00 + + // Show output for local time + let thisDate = DateTimeOffset.Now + printfn $"{thisDate.ToString()}" // Displays 3/28/2007 12:13:50 PM -07:00 + + // Show output for arbitrary time offset + let thisDate = thisDate.ToOffset(TimeSpan(-5, 0, 0)) + printfn $"{thisDate.ToString()}" // Displays 3/28/2007 2:13:50 PM -05:00 + // + +let toString2 () = + // + let cultures = + [| CultureInfo.InvariantCulture + CultureInfo "en-us" + CultureInfo "fr-fr" + CultureInfo "de-DE" + CultureInfo "es-ES" |] + + let thisDate = DateTimeOffset(2007, 5, 1, 9, 0, 0, TimeSpan.Zero) + + for culture in cultures do + let cultureName = + if String.IsNullOrEmpty culture.Name then + culture.NativeName + else + culture.Name + printfn $"In {cultureName}, {thisDate.ToString culture}" + + // The example produces the following output: + // In Invariant Language (Invariant Country), 05/01/2007 09:00:00 +00:00 + // In en-US, 5/1/2007 9:00:00 AM +00:00 + // In fr-FR, 01/05/2007 09:00:00 +00:00 + // In de-DE, 01.05.2007 09:00:00 +00:00 + // In es-ES, 01/05/2007 9:00:00 +00:00 + // + +let toString3 () = + // + let outputDate = DateTimeOffset(2007, 10, 31, 21, 0, 0, TimeSpan(-8, 0, 0)) + + // Output date using each standard date/time format specifier + let specifier = "d" + // Displays d: 10/31/2007 + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "D" + // Displays D: Wednesday, October 31, 2007 + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "t" + // Displays t: 9:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "T" + // Displays T: 9:00:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "f" + // Displays f: Wednesday, October 31, 2007 9:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "F" + // Displays F: Wednesday, October 31, 2007 9:00:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "g" + // Displays g: 10/31/2007 9:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "G" + // Displays G: 10/31/2007 9:00:00 PM + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "M" // 'm' is identical + // Displays M: October 31 + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "R" // 'r' is identical + // Displays R: Thu, 01 Nov 2007 05:00:00 GMT + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "s" + // Displays s: 2007-10-31T21:00:00 + printfn $"{specifier}: {outputDate.ToString specifier}" + + let specifier = "u" + // Displays u: 2007-11-01 05:00:00Z + printfn $"{specifier}: {outputDate.ToString specifier}" + + // Specifier is not supported + let specifier = "U" + try + printfn $"{specifier}: {outputDate.ToString specifier}" + with :? FormatException -> + printfn $"{specifier}: Not supported." + + let specifier = "Y" // 'y' is identical + // Displays Y: October, 2007 + printfn $"{specifier}: {outputDate.ToString specifier}" + // + +let toString4 () = + // + let outputDate = DateTimeOffset(2007, 11, 1, 9, 0, 0, TimeSpan(-7, 0, 0)) + let format = "dddd, MMM dd yyyy HH:mm:ss zzz" + + // Output date and time using custom format specification + printfn $"{outputDate.ToString(format, null)}" + printfn $"{outputDate.ToString(format, CultureInfo.InvariantCulture)}" + printfn $"""{outputDate.ToString(format, CultureInfo "fr-FR")}""" + printfn $"""{outputDate.ToString(format, CultureInfo "es-ES")}""" + + // The example displays the following output to the console: + // Thursday, Nov 01 2007 09:00:00 -07:00 + // Thursday, Nov 01 2007 09:00:00 -07:00 + // jeudi, nov. 01 2007 09:00:00 -07:00 + // jueves, nov 01 2007 09:00:00 -07:00 + // + +toString1 () +printfn "" +toString2 () +printfn "" +toString3 () +printfn "" +toString4 () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/fs.fsproj new file mode 100644 index 00000000000..38881a8fd46 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs new file mode 100644 index 00000000000..61128a16ae9 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs @@ -0,0 +1,83 @@ +open System +open System.Globalization + +let tryParse1 () = + // + // String with date only + let dateString = "05/01/2008" + match DateTimeOffset.TryParse dateString with + | true, parsedDate -> + printfn $"{dateString} was converted to {parsedDate}." + | _ -> () + + // String with time only + let dateString = "11:36 PM" + match DateTimeOffset.TryParse dateString with + | true, parsedDate -> + printfn $"{dateString} was converted to {parsedDate}." + | _ -> () + + // String with date and offset + let dateString = "05/01/2008 +7:00" + match DateTimeOffset.TryParse dateString with + | true, parsedDate -> + printfn $"{dateString} was converted to {parsedDate}." + | _ -> () + + // String with day abbreviation + let dateString = "Thu May 01, 2008" + match DateTimeOffset.TryParse dateString with + | true, parsedDate -> + printfn $"{dateString} was converted to {parsedDate}." + | _ -> () + + // String with date, time with AM/PM designator, and offset + let dateString = "5/1/2008 10:00 AM -07:00" + match DateTimeOffset.TryParse dateString with + | true, parsedDate -> + printfn $"{dateString} was converted to {parsedDate}." + | _ -> () + + // if (run on 3/29/07, the example displays the following output + // to the console: + // 05/01/2008 was converted to 5/1/2008 12:00:00 AM -07:00. + // 11:36 PM was converted to 3/29/2007 11:36:00 PM -07:00. + // 05/01/2008 +7:00 was converted to 5/1/2008 12:00:00 AM +07:00. + // Thu May 01, 2008 was converted to 5/1/2008 12:00:00 AM -07:00. + // 5/1/2008 10:00 AM -07:00 was converted to 5/1/2008 10:00:00 AM -07:00. + // + +let tryParse2 () = + // + let dateString = "05/01/2008 6:00:00" + // Assume time is local + match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AssumeLocal) with + | true, parsedDate -> + printfn $"'{dateString}' was converted to {parsedDate}." + | _ -> + printfn $"Unable to parse '{dateString}'." + + // Assume time is UTC + match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AssumeUniversal) with + | true, parsedDate -> + printfn $"'{dateString}' was converted to {parsedDate}." + | _ -> + printfn $"Unable to parse '{dateString}'." + + // Parse and convert to UTC + let dateString = "05/01/2008 6:00:00AM +5:00" + match DateTimeOffset.TryParse(dateString, null, DateTimeStyles.AdjustToUniversal) with + | true, parsedDate -> + printfn $"'{dateString}' was converted to {parsedDate}." + | _ -> + printfn $"Unable to parse '{dateString}'." + + // The example displays the following output to the console: + // '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM -07:00. + // '05/01/2008 6:00:00' was converted to 5/1/2008 6:00:00 AM +00:00. + // '05/01/2008 6:00:00AM +5:00' was converted to 5/1/2008 1:00:00 AM +00:00. + // + +tryParse1 () +printfn "" +tryParse2 () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/fs.fsproj new file mode 100644 index 00000000000..f280b3ec57e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs new file mode 100644 index 00000000000..f733ed1ac6d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs @@ -0,0 +1,115 @@ +open System +open System.Globalization +open System.IO + +let tryParseExact1 () = + // + let provider = CultureInfo.InvariantCulture + + // Parse date-only value with invariant culture and assume time is UTC. + let dateString = "06/15/2008" + let format = "d" + match DateTimeOffset.TryParseExact(dateString, format, provider, DateTimeStyles.AssumeUniversal) with + | true, result -> + printfn $"'{dateString}' converts to {result}." + | _ -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date-only value with leading white space. + // Should return False because only trailing white space is + // specified in method call. + let dateString = " 06/15/2008" + match DateTimeOffset.TryParseExact(dateString, format, provider, DateTimeStyles.AllowTrailingWhite) with + | true, result -> + printfn $"'{dateString}' converts to {result}." + | _ -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date and time value, and allow all white space. + let dateString = " 06/15/ 2008 15:15 -05:00" + let format = "MM/dd/yyyy H:mm zzz" + match DateTimeOffset.TryParseExact(dateString, format, provider, DateTimeStyles.AllowWhiteSpaces) with + | true, result -> + printfn $"'{dateString}' converts to {result}." + | _ -> + printfn $"'{dateString}' is not in the correct format." + + // Parse date and time and convert to UTC. + let dateString = " 06/15/2008 15:15:30 -05:00" + let format = "MM/dd/yyyy H:mm:ss zzz" + match DateTimeOffset.TryParseExact(dateString, format, provider, DateTimeStyles.AllowWhiteSpaces ||| DateTimeStyles.AdjustToUniversal) with + | true, result -> + printfn $"'{dateString}' converts to {result}." + | _ -> + printfn $"'{dateString}' is not in the correct format." + + // The example displays the following output: + // '06/15/2008' converts to 6/15/2008 12:00:00 AM +00:00. + // ' 06/15/2008' is not in the correct format. + // ' 06/15/ 2008 15:15 -05:00' converts to 6/15/2008 3:15:00 PM -05:00. + // ' 06/15/2008 15:15:30 -05:00' converts to 6/15/2008 8:15:30 PM +00:00. + // + +let tryParseExact2 () = + // + let mutable result = None + let mutable tries = 0 + let mutable input = "" + + let formats = + [| "M/dd/yyyy HH:m zzz"; "MM/dd/yyyy HH:m zzz" + "M/d/yyyy HH:m zzz"; "MM/d/yyyy HH:m zzz" + "M/dd/yy HH:m zzz"; "MM/dd/yy HH:m zzz" + "M/d/yy HH:m zzz"; "MM/d/yy HH:m zzz" + "M/dd/yyyy H:m zzz"; "MM/dd/yyyy H:m zzz" + "M/d/yyyy H:m zzz"; "MM/d/yyyy H:m zzz" + "M/dd/yy H:m zzz"; "MM/dd/yy H:m zzz" + "M/d/yy H:m zzz"; "MM/d/yy H:m zzz" + "M/dd/yyyy HH:mm zzz"; "MM/dd/yyyy HH:mm zzz" + "M/d/yyyy HH:mm zzz"; "MM/d/yyyy HH:mm zzz" + "M/dd/yy HH:mm zzz"; "MM/dd/yy HH:mm zzz" + "M/d/yy HH:mm zzz"; "MM/d/yy HH:mm zzz" + "M/dd/yyyy H:mm zzz"; "MM/dd/yyyy H:mm zzz" + "M/d/yyyy H:mm zzz"; "MM/d/yyyy H:mm zzz" + "M/dd/yy H:mm zzz"; "MM/dd/yy H:mm zzz" + "M/d/yy H:mm zzz"; "MM/d/yy H:mm zzz" |] + let provider = CultureInfo.InvariantCulture.DateTimeFormat + + while tries < 3 && result.IsNone do + printfn "Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM)," + printf "Then press Enter: " + input <- stdin.ReadLine() + printfn "" + match DateTimeOffset.TryParseExact(input, formats, provider, DateTimeStyles.AllowWhiteSpaces) with + | true, dto -> + result <- Some dto + | _ -> + printfn $"Unable to parse {input}." + tries <- tries + 1 + + match result with + | Some result -> + printfn $"{input} was converted to {result}" + | None -> + printfn $"Exiting application without parsing {input}" + + // Some successful sample interactions with the user might appear as follows: + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/08/2007 6:54 -6:00 + // + // 12/08/2007 6:54 -6:00 was converted to 12/8/2007 6:54:00 AM -06:00 + // + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/8/2007 06:54 -06:00 + // + // 12/8/2007 06:54 -06:00 was converted to 12/8/2007 6:54:00 AM -06:00 + // + // Enter a date, time, and offset (MM/DD/YYYY HH:MM +/-HH:MM), + // Then press Enter: 12/5/07 6:54 -6:00 + // + // 12/5/07 6:54 -6:00 was converted to 12/5/2007 6:54:00 AM -06:00 + // + +tryParseExact1 () +printfn "" +tryParseExact2 () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/fs.fsproj new file mode 100644 index 00000000000..4eb1466dc75 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs new file mode 100644 index 00000000000..57e89e6832a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs @@ -0,0 +1,20 @@ +// +open System + +// Find difference between Date.Now and Date.UtcNow +let date1 = DateTime.Now +let date2 = DateTime.UtcNow +let difference1 = date1 - date2 +printfn $"{date1} - {date2} = {difference1}" + +// Find difference between Now and UtcNow using DateTimeOffset +let dateOffset1 = DateTimeOffset.Now +let dateOffset2 = DateTimeOffset.UtcNow +let difference2 = dateOffset1 - dateOffset2 +printfn $"{dateOffset1} - {dateOffset2} = {difference2}" + +// If run in the Pacific Standard time zone on 1/7/2022, the example +// displays the following output to the console: +// 1/7/2022 6:45:10 PM - 1/8/2022 2:45:10 AM = -08:00:00.0072573 +// 1/7/2022 6:45:10 PM -08:00 - 1/8/2022 2:45:10 AM +00:00 = -00:00:00.0000278 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/fs.fsproj new file mode 100644 index 00000000000..8b3bf26ba17 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/fs.fsproj new file mode 100644 index 00000000000..1a662e03c7d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs new file mode 100644 index 00000000000..90aee82a305 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs @@ -0,0 +1,32 @@ +// +open System + +let fmtStrings = + [ "d"; "D"; "f"; "F"; "g"; "G"; "M" + "R"; "s"; "t"; "T"; "u"; "y" ] + +let value = DateTimeOffset.Now +// Display date in default format. +printfn $"{value}\n" + +// Display date using each of the specified formats. +for fmtString in fmtStrings do + printfn $"{fmtString} --> {value.ToString fmtString}" + +// The example displays output similar to the following: +// 11/19/2012 10:57:11 AM -08:00 +// +// d --> 11/19/2012 +// D --> Monday, November 19, 2012 +// f --> Monday, November 19, 2012 10:57 AM +// F --> Monday, November 19, 2012 10:57:11 AM +// g --> 11/19/2012 10:57 AM +// G --> 11/19/2012 10:57:11 AM +// M --> November 19 +// R --> Mon, 19 Nov 2012 18:57:11 GMT +// s --> 2012-11-19T10:57:11 +// t --> 10:57 AM +// T --> 10:57:11 AM +// u --> 2012-11-19 18:57:11Z +// y --> November, 2012 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs new file mode 100644 index 00000000000..407fd3d984c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs @@ -0,0 +1,18 @@ +module argumentoutofrangeexception1 + +// +open System +open System.Globalization + +let jaJP = CultureInfo "ja-JP" +jaJP.DateTimeFormat.Calendar <- JapaneseCalendar() +let date1 = DateTimeOffset(DateTime(1867, 1, 1), TimeSpan.Zero) + +try + printfn $"{date1.ToString jaJP}" +with :? ArgumentOutOfRangeException -> + printfn $"{date1:d} is earlier than {jaJP.DateTimeFormat.Calendar.MinSupportedDateTime:d} or later than {jaJP.DateTimeFormat.Calendar.MaxSupportedDateTime:d}" + +// The example displays the following output: +// 1/1/1867 is earlier than 9/8/1868 or later than 12/31/9999 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs new file mode 100644 index 00000000000..213a42e0138 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs @@ -0,0 +1,28 @@ +module argumentoutofrangeexception2 + +// +open System +open System.Globalization +open System.Threading + +let date1 = DateTimeOffset(DateTime(550, 1, 1), TimeSpan.Zero) + +let arSY = CultureInfo "ar-SY" +arSY.DateTimeFormat.Calendar <- HijriCalendar() + +// Change current culture to ar-SY. +let dft = Thread.CurrentThread.CurrentCulture +Thread.CurrentThread.CurrentCulture <- arSY + +// Display the date using the current culture's calendar. +try + printfn $"{date1}" +with :? ArgumentOutOfRangeException -> + printfn $"""{date1.ToString("d", CultureInfo.InvariantCulture)} is earlier than {arSY.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture)} or later than {arSY.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture)}""" + +// Restore the default culture. +Thread.CurrentThread.CurrentCulture <- dft + +// The example displays the following output: +// 01/01/0550 is earlier than 07/18/0622 or later than 12/31/9999 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs new file mode 100644 index 00000000000..7a90674b6a8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs @@ -0,0 +1,28 @@ +module argumentoutofrangeexception3 + +// +open System +open System.Globalization +open System.Threading + +let date1 = DateTimeOffset(DateTime(1550, 7, 21), TimeSpan.Zero) + +let heIL = CultureInfo "he-IL" +heIL.DateTimeFormat.Calendar <- HebrewCalendar() + +// Change current culture to he-IL. +let dft = Thread.CurrentThread.CurrentCulture +Thread.CurrentThread.CurrentCulture <- heIL + +// Display the date using the current culture's calendar. +try + printfn $"{date1:G}" +with :? ArgumentOutOfRangeException -> + printfn $"""{date1.ToString("d", CultureInfo.InvariantCulture)} is earlier than {heIL.DateTimeFormat.Calendar.MinSupportedDateTime.ToString("d", CultureInfo.InvariantCulture)} or later than {heIL.DateTimeFormat.Calendar.MaxSupportedDateTime.ToString("d", CultureInfo.InvariantCulture)}""" + +// Restore the default culture. +Thread.CurrentThread.CurrentCulture <- dft + +// The example displays the following output: +// 07/21/1550 is earlier than 01/01/1583 or later than 09/29/2239 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs new file mode 100644 index 00000000000..66215fa20ba --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs @@ -0,0 +1,18 @@ +module argumentoutofrangeexception4 + +// +open System +open System.Globalization + +let arSA = CultureInfo "ar-SA" +arSA.DateTimeFormat.Calendar <- UmAlQuraCalendar() +let date1 = DateTimeOffset(DateTime(1890, 9, 10), TimeSpan.Zero) + +try + printfn $"""{date1.ToString("d", arSA)}""" +with :? ArgumentOutOfRangeException -> + printfn $"{date1:d} is earlier than {arSA.DateTimeFormat.Calendar.MinSupportedDateTime:d} or later than {arSA.DateTimeFormat.Calendar.MaxSupportedDateTime:d}" + +// The example displays the following output: +// 9/10/1890 is earlier than 4/30/1900 or later than 11/16/2077 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/fs.fsproj new file mode 100644 index 00000000000..9da80c564b9 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/fs.fsproj @@ -0,0 +1,12 @@ + + + Exe + net6.0 + + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/fs.fsproj new file mode 100644 index 00000000000..e180b733549 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/fs.fsproj @@ -0,0 +1,9 @@ + + + Exe + net6.0 + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs new file mode 100644 index 00000000000..9a2a9d46924 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs @@ -0,0 +1,20 @@ +// +open System + +[] +let main _ = + let dto = DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero) + printfn $"{dto} --> Unix Seconds: {dto.ToUnixTimeSeconds()}" + + let dto = DateTimeOffset(1969, 12, 31, 23, 59, 0, TimeSpan.Zero) + printfn $"{dto} --> Unix Seconds: {dto.ToUnixTimeSeconds()}" + + let dto = DateTimeOffset(1970, 1, 1, 0, 1, 0, TimeSpan.Zero) + printfn $"{dto} --> Unix Seconds: {dto.ToUnixTimeSeconds()}" + + 0 +// The example displays the following output: +// 1/1/1970 12:00:00 AM +00:00 --> Unix Seconds: 0 +// 12/31/1969 11:59:00 PM +00:00 --> Unix Seconds: -60 +// 1/1/1970 12:01:00 AM +00:00 --> Unix Seconds: 60 +// \ No newline at end of file diff --git a/xml/System/DateTimeOffset.xml b/xml/System/DateTimeOffset.xml index 48d895ae471..c15e3801638 100644 --- a/xml/System/DateTimeOffset.xml +++ b/xml/System/DateTimeOffset.xml @@ -106,6 +106,7 @@ You can add or subtract either dates or time intervals from a particular value. Arithmetic operations with values, unlike those with values, adjust for differences in time offsets when returning a result. For example, the following code uses variables to subtract the current local time from the current UTC time. The code then uses variables to perform the same operation. The subtraction with values returns the local time zone's difference from UTC, while the subtraction with values returns . :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/cs/Type.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Type/fs/Type.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Type/vb/Type.vb" id="Snippet1"::: - Type conversion operations. @@ -201,6 +202,7 @@ The following example illustrates how the value of the property of the `dateTime` parameter affects the date and time value that is returned by this constructor. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet1"::: ]]> @@ -270,6 +272,7 @@ The following example shows how to initialize a object with a date and time and the offset of the local time zone when that time zone is not known in advance. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet3"::: ]]> @@ -339,6 +342,7 @@ Ordinarily, trying to call the constructor to instantiate a value with a local time and an offset other than that of the local time zone throws an . You can use this overload of the constructor to work around this limitation. The following example uses the local time's number of ticks to instantiate a value whose offset does not necessarily represent that of the local time: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet4"::: @@ -347,6 +351,7 @@ The following example initializes a object by using the number of ticks in an arbitrary date (in this case, July 16, 2007, at 1:32 PM) with an offset of -5. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet2"::: ]]> @@ -426,6 +431,7 @@ The following example instantiates a object by using the constructor overload. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet5"::: ]]> @@ -528,6 +534,7 @@ The following example instantiates a object by using the constructor overload. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet7"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet7"::: ]]> @@ -632,6 +639,7 @@ The following example uses instances of both the class and the class to instantiate a value. That date is then displayed to the console using the respective calendars and the Gregorian calendar. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/cs/Constructors.cs" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/fs/Constructors.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Constructors/vb/Constructors.vb" id="Snippet8"::: ]]> @@ -743,6 +751,7 @@ The following example creates an array of objects that represent the flight times between destinations. The method then adds these times to a object that represents a flight's initial takeoff time. The result reflects the scheduled arrival time at each destination. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet1"::: ]]> @@ -816,6 +825,7 @@ The following example uses the method to list the dates that fall on Monday, the start of the work week, in March 2008. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet2"::: ]]> @@ -887,6 +897,7 @@ The following example uses the method to list the start times of work shifts for a particular week at an office that has two eight-hour shifts per day. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet3"::: ]]> @@ -1081,6 +1092,7 @@ The following example uses the method to display the start date of each quarter of the year 2007. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet4"::: ]]> @@ -1293,6 +1305,7 @@ In the United States, driver's licenses cannot be issued to persons under 16 years of age. The following example displays the latest possible date on which a person must be born in order to legally be issued a driver's license. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet6"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet6"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet6"::: ]]> @@ -1372,6 +1385,7 @@ In performing the comparison, the method converts both the `first` and the `second` parameters to Coordinated Universal Time (UTC) before it performs the comparison. The method is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet1"::: In other words, the method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. @@ -1382,6 +1396,7 @@ The following example illustrates calls to the method to compare objects. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods2.cs" id="Snippet7"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods2.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods2.vb" id="Snippet7"::: ]]> @@ -1462,6 +1477,7 @@ The following example illustrates calls to the method to compare objects. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods3.cs" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods3.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods3.vb" id="Snippet8"::: ]]> @@ -1521,6 +1537,7 @@ The following example retrieves the value of the property for a specific date. It then displays that value to the console using some standard and custom date-only format specifiers. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet1"::: ]]> @@ -1582,6 +1599,7 @@ The following example illustrates the use of the property to convert the time returned by the and properties to values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet2"::: ]]> @@ -1647,6 +1665,7 @@ - By calling the method with the "dd" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet10"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet10"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet10"::: ]]> @@ -1699,11 +1718,13 @@ You can also display the weekday name of a particular date by using the "D" format specifier or the "dddd" custom format specifier. For example: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet4"::: Note that the string returned by calling the `ToString` method of the enumeration member that is returned by this property is not localized. To extract a string that contains the weekday name of the current culture or of a specific culture, call the method with the "dddd" custom format specifier. For example, the following code displays the weekday name for a date using the `fr-fr` culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet5"::: @@ -1712,6 +1733,7 @@ The following example displays the weekday name of the first day of each month of the year 2008. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet3"::: ]]> @@ -1823,6 +1845,7 @@ Before it performs the comparison, this method converts the values of both objects to Coordinated Universal Time (UTC). The method is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet2"::: In other words, the method determines whether two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. @@ -1837,6 +1860,7 @@ The following example illustrates calls to the method to test objects for equality with the current object. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet9"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet9"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet9"::: ]]> @@ -1894,6 +1918,7 @@ Before it performs the comparison, this method converts the values of both the current object and the `obj` parameter to Coordinated Universal Time (UTC). The method is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet3"::: In other words, the method determines whether the current object and a specified object represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. @@ -1906,6 +1931,7 @@ The following example indicates whether the current object is equal to several other objects, as well as to a null reference and a object. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet10"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet10"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet10"::: ]]> @@ -1964,6 +1990,7 @@ Before it performs the comparison, this method converts both objects to Coordinated Universal Time (UTC). The method is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. @@ -1974,6 +2001,7 @@ The following example illustrates calls to the method to test various pairs of objects for equality. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet11"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet11"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet11"::: ]]> @@ -2037,6 +2065,7 @@ The following example illustrates the use of the method to compare similar objects. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet12"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet12"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet12"::: ]]> @@ -2101,6 +2130,7 @@ The following example uses the Windows API to retrieve the Windows file times for the WordPad executable. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/cs/FileTime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/fs/FileTime.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.FromFileTime/vb/FileTime.vb" id="Snippet1"::: ]]> @@ -2323,6 +2353,7 @@ - By calling the method with the "HH" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet6"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet6"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet6"::: ]]> @@ -2386,6 +2417,7 @@ The following example illustrates several conversions of values to local times in the U.S. Pacific Standard Time zone. Note that the last three times are all ambiguous; the property maps all of them to a single date and time in the Pacific Standard Time zone. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet7"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet7"::: ]]> @@ -2496,6 +2528,7 @@ The following example displays the number of milliseconds of a object by using a custom format specifier and by directly accessing the property. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet12"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet12"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet12"::: ]]> @@ -2559,6 +2592,7 @@ - By calling the method with the "mm" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet8"::: ]]> @@ -2671,6 +2705,7 @@ - By calling the method with the "MM" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet9"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet9"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet9"::: ]]> @@ -2726,11 +2761,13 @@ The following example uses the property to retrieve the current date and time and displays it by using each of the [standard date and time format strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) supported by the type. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.now/cs/now1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.now/fs/now1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.now/vb/now1.vb" id="Snippet1"::: The following example uses the and properties to determine the resolution of the system clock. It displays the time only when the value of its millisecond component has changed. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet11"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet11"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet11"::: ]]> @@ -2789,6 +2826,7 @@ The following example uses the property to display the local time's difference from Coordinated Universal Time (UTC). :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet13"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet13"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet13"::: ]]> @@ -2852,6 +2890,7 @@ The method defines the addition operation for values. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet1"::: Languages that do not support custom operators and operator overloading can call the method instead. @@ -2918,11 +2957,13 @@ The method defines the operation of the equality operator for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet2"::: Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: In other words, the method determines whether the two objects represent a single point in time. It directly compares neither dates and times nor offsets. To determine whether two objects represent the same time and have the same offset value, use the method. @@ -2983,6 +3024,7 @@ The method defines the operation of the greater than operator for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet3"::: Languages that do not support custom operators can call the method instead. They can also call the method directly, as the following example shows. @@ -2992,6 +3034,7 @@ Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet5"::: The equivalent method for this operator is ]]> @@ -3049,6 +3092,7 @@ The method defines the operation of the greater than or equal to operator for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet5"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -3058,6 +3102,7 @@ Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet6"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet6"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet6"::: The equivalent method for this operator is ]]> @@ -3112,6 +3157,7 @@ The method enables the compiler to automatically convert a object to a object without an explicit casting operator (in C#) or a call to a conversion function (in Visual Basic). It defines a widening conversion that does not involve data loss and does not throw an . The method makes code such as the following possible: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet7"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet7"::: This method is equivalent to the constructor. The offset of the resulting object depends on the value of the property of the `dateTime` parameter: @@ -3180,11 +3226,13 @@ The method defines the operation of the inequality operator for objects. It always returns the opposite result from . The method enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet8"::: Before evaluating the `left` and `right` operands for equality, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet4"::: In other words, the method determines whether the two objects represent different points in time. It directly compares neither dates and times nor offsets. @@ -3248,11 +3296,13 @@ The method defines the operation of the less than operator for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet10"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet10"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet10"::: Before evaluating the `left` and `right` operands, the operator converts both operands to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet8"::: Languages that do not support custom operators can call the method instead. In addition, some languages can also call the method directly, as the following example shows. @@ -3314,6 +3364,7 @@ The method defines the operation of the less than or equal to operator for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet12"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet12"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet12"::: Languages that do not support custom operators can call the method instead. Some languages can also call the method directly, as the following example shows. @@ -3323,6 +3374,7 @@ Before evaluating the `left` and `right` operands, the operator converts both values to Coordinated Universal Time (UTC). The operation is equivalent to the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/cs/Syntax.cs" id="Snippet9"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/fs/Syntax.fs" id="Snippet9"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Syntax/vb/Syntax.vb" id="Snippet9"::: The equivalent method for this operator is ]]> @@ -3392,6 +3444,7 @@ The method defines the subtraction operation for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet14"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet14"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet14"::: Languages that do not support custom operators and operator overloading can call the method instead. @@ -3459,6 +3512,7 @@ The method defines the subtraction operation for objects. It enables code such as the following: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/cs/Operators.cs" id="Snippet15"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/fs/Operators.fs" id="Snippet15"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Operators/vb/Operators.vb" id="Snippet15"::: Languages that do not support custom operators and operator overloading can call the method instead. @@ -3559,6 +3613,7 @@ The following example calls the method to parse several date and time strings. The example includes output from March 22, 2007, on a system whose culture is en-us. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/cs/ParseExamples.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/vb/ParseExamples.vb" id="Snippet1"::: ]]> @@ -3650,6 +3705,7 @@ The following example parses date and time strings that are formatted for the fr-fr culture and displays them using the local system's default en-us culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/cs/ParseExamples.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/vb/ParseExamples.vb" id="Snippet2"::: ]]> @@ -3806,6 +3862,7 @@ The following example illustrates the effect of passing the , , and values to the `styles` parameter of the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/cs/ParseExamples.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/fs/ParseExamples.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Parse/vb/ParseExamples.vb" id="Snippet3"::: ]]> @@ -3923,11 +3980,13 @@ The following example uses the method with standard and custom format specifiers and the invariant culture to parse several date and time strings. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/cs/ParseExact.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/vb/ParseExact.vb" id="Snippet1"::: The following example parses an array of strings that are expected to conform to [ISO 8601](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). As the output from the example shows, strings with leading or trailing spaces fail to parse successfully, as do strings with date and time elements that are out of range. :::code language="csharp" source="~/samples/snippets/csharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.cs" interactive="try-dotnet"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601.fs"::: :::code language="vb" source="~/samples/snippets/visualbasic/api/system/datetimeoffset/parseexact/parseexact-iso8601.vb"::: @@ -4213,6 +4272,7 @@ The hour component and the AM/PM designator in do not The following example uses the method with standard and custom format specifiers, the invariant culture, and various values to parse several date and time strings. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/cs/ParseExact.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/vb/ParseExact.vb" id="Snippet2"::: The following example uses a variety of values to parse an array of strings that are expected to conform to [ISO 8601](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). As the output from the example shows, strings that are in the proper format fail to parse if: @@ -4224,6 +4284,7 @@ The following example uses a variety of flag is supplied in the method call. In that case, they are assumed to be Universal Coordinated Time. :::code language="csharp" source="~/samples/snippets/csharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.cs" interactive="try-dotnet"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System/DateTimeOffset.ParseExact/parseexact-iso8601-2.fs"::: :::code language="vb" source="~/samples/snippets/visualbasic/api/system/datetimeoffset/parseexact/parseexact-iso8601-2.vb"::: @@ -4355,6 +4416,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/cs/ParseExact.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/fs/ParseExact.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ParseExact/vb/ParseExact.vb" id="Snippet3"::: ]]> @@ -4449,6 +4511,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l - By calling the method with the "ss" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet14"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet14"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet14"::: ]]> @@ -4526,6 +4589,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example illustrates subtraction that uses the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet13"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet13"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet13"::: ]]> @@ -4593,6 +4657,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example illustrates subtraction that uses the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet14"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet14"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet14"::: ]]> @@ -4816,6 +4881,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example initializes a object by approximating the number of ticks in the date July 1, 2008 1:23:07. It then displays the date and the number of ticks represented by that date to the console. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet15"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet15"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet15"::: ]]> @@ -4874,6 +4940,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example uses the property to extract the time and display it to the console. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet16"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet16"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet16"::: ]]> @@ -4994,6 +5061,7 @@ Me.ToUtcDateTime().ToFileTime() The following example uses the method to convert a value to local time in the Pacific Standard Time zone. It also illustrates the method's support for the local time zone's adjustment rules. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet15"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet15"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet15"::: ]]> @@ -5054,6 +5122,7 @@ Me.ToUtcDateTime().ToFileTime() The following example illustrates how to use the method to convert a object to a object with a different offset. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/cs/ToOffset.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/fs/ToOffset.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToOffset/vb/ToOffset.vb" id="Snippet1"::: ]]> @@ -5147,6 +5216,7 @@ Me.ToUtcDateTime().ToFileTime() The following example illustrates calls to the method and displays its output on a system whose current culture is en-us. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/cs/ToString.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet1"::: ]]> @@ -5156,6 +5226,7 @@ Me.ToUtcDateTime().ToFileTime() The method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class when the current culture is Arabic (Syria). :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/cs/datetimeoffset.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: @@ -5228,6 +5299,7 @@ Me.ToUtcDateTime().ToFileTime() The following example displays a object using objects that represent the invariant culture, as well as four other cultures. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/cs/ToString.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet2"::: ]]> @@ -5237,6 +5309,7 @@ Me.ToUtcDateTime().ToFileTime() The method returns the string representation of the date and time in the calendar used by the culture represented by the parameter. Its calendar is defined by the property. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/cs/datetimeoffset.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: @@ -5314,6 +5387,7 @@ Me.ToUtcDateTime().ToFileTime() The following example displays a object to the console using each of the standard date and time format specifiers. The output is formatted by using the en-us culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/cs/ToString.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet3"::: ]]> @@ -5328,6 +5402,7 @@ Me.ToUtcDateTime().ToFileTime() The method returns the string representation of the date and time in the calendar used by the current culture. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class when the current culture is Hebrew (Israel). :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/cs/datetimeoffset.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: Standard Date and Time Format Strings @@ -5418,6 +5493,7 @@ Me.ToUtcDateTime().ToFileTime() The following example uses the method to display a object using a custom format string for several different cultures. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/cs/ToString.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/fs/ToString.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.ToString/vb/ToString.vb" id="Snippet4"::: ]]> @@ -5432,6 +5508,7 @@ Me.ToUtcDateTime().ToFileTime() The method returns the string representation of the date and time in the calendar used by the parameter. Its calendar is defined by the property. If the value of the current instance is earlier than or later than , the method throws an . The following example provides an illustration. It attempts to format a date that is outside the range of the class. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/cs/datetimeoffset.tostring.argumentoutofrangeexception4.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/fs/datetimeoffset.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tostring.argumentoutofrangeexception/vb/datetimeoffset.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: Standard Date and Time Format Strings @@ -5492,6 +5569,7 @@ Me.ToUtcDateTime().ToFileTime() The following example calls the method to convert a local time and several other times to Coordinated Universal Time (UTC). :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/cs/Methods.cs" id="Snippet16"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/fs/Methods.fs" id="Snippet16"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Methods/vb/Methods.vb" id="Snippet16"::: ]]> @@ -5598,6 +5676,7 @@ Me.ToUtcDateTime().ToFileTime() The following example calls the method to return the Unix time of values that are equal to, shortly before, and shortly after 1970-01-01T00:00:00Z. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/cs/tounixtimeseconds1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/fs/tounixtimeseconds1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetimeoffset.tounixtimeseconds/vb/tounixtimeseconds1.vb" id="Snippet1"::: ]]> @@ -5782,6 +5861,7 @@ Me.ToUtcDateTime().ToFileTime() The following example calls the method to parse several strings with various date and time formats. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/cs/TryParse.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/vb/TryParse.vb" id="Snippet1"::: ]]> @@ -5937,6 +6017,7 @@ Me.ToUtcDateTime().ToFileTime() The following example calls the method with a variety of values to parse some strings with various date and time formats. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/cs/TryParse.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/fs/TryParse.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParse/vb/TryParse.vb" id="Snippet2"::: ]]> @@ -6233,6 +6314,7 @@ This method parses the string representation of a date that matches any one of t The following example uses the method with standard and custom format specifiers, the invariant culture, and various values to parse several date and time strings. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/cs/TryParseExact.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet1"::: The following example uses a variety of values to parse an array of strings that are expected to conform to [ISO 8601](/dotnet/standard/base-types/standard-date-and-time-format-strings#the-round-trip-o-o-format-specifier). As the output from the example shows, strings that are in the proper format fail to parse if: @@ -6244,6 +6326,7 @@ The following example uses a variety of flag is supplied in the method call. In that case, they are assumed to be Universal Coordinated Time. :::code language="csharp" source="~/samples/snippets/csharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.cs"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System/DateTimeOffset.TryParseExact/tryparseexacto8601-2.fs"::: :::code language="vb" source="~/samples/snippets/visualbasic/api/system/datetimeoffset/tryparseexact/tryparseexacto8601-2.vb"::: ]]> @@ -6356,6 +6439,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example defines multiple input formats for the string representation of a date and time and offset value, and then passes the string that is entered by the user to the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/cs/TryParseExact.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/fs/TryParseExact.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.TryParseExact/vb/TryParseExact.vb" id="Snippet2"::: ]]> @@ -6462,6 +6546,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example shows how to use of the property to display a value and its corresponding UTC time. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet17"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet17"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet17"::: ]]> @@ -6519,6 +6604,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l The following example illustrates the relationship between Coordinated Universal Time (UTC) and local time. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet18"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet18"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet18"::: ]]> @@ -6632,6 +6718,7 @@ Strings that do not specify a UTC offset are assumed to have the offset of the l - By calling the method with the "yyyy" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/cs/Properties.cs" id="Snippet19"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/fs/Properties.fs" id="Snippet19"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTimeOffset.Properties/vb/Properties.vb" id="Snippet19"::: ]]>