From 696ced849acae641325c831d411c92184d98693a Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Tue, 4 Jan 2022 21:03:21 -0800 Subject: [PATCH 1/2] System.DateTime F# snippets --- .../fsharp/System.DateTime/Calendar.fs | 108 +++++ .../System.DateTime/DateTimeComparisons.fs | 53 +++ .../System.DateTime/DateWithTimeZone.fs | 18 + .../fsharp/System.DateTime/Instantiation.fs | 42 ++ .../fsharp/System.DateTime/Parsing.fs | 64 +++ .../fsharp/System.DateTime/Persistence.fs | 412 ++++++++++++++++++ .../fsharp/System.DateTime/Resolution.fs | 19 + .../fsharp/System.DateTime/StringFormat.fs | 44 ++ .../snippets/fsharp/System.DateTime/fs.fsproj | 16 + .../DateTime Operators/FS/class1.fs | 31 ++ .../DateTime Operators/FS/fs.fsproj | 9 + .../VS_Snippets_CLR/DateTime.Add/FS/class1.fs | 9 + .../VS_Snippets_CLR/DateTime.Add/FS/fs.fsproj | 9 + .../DateTime.AddDays/FS/class1.fs | 13 + .../DateTime.AddDays/FS/fs.fsproj | 9 + .../FS/CompareTo_CS1_24564.fs | 31 ++ .../DateTime.CompareTo.2/FS/fs.fsproj | 9 + .../DateTime.CompareTo/FS/class1.fs | 19 + .../DateTime.CompareTo/FS/fs.fsproj | 9 + .../DateTime.DayOfWeek/FS/dow.fs | 15 + .../DateTime.DayOfWeek/FS/fs.fsproj | 9 + .../DateTime.DaysInMonth/FS/class1.fs | 22 + .../DateTime.DaysInMonth/FS/fs.fsproj | 9 + .../DateTime.Equals/FS/class1.fs | 20 + .../DateTime.Equals/FS/fs.fsproj | 9 + .../DateTime.FromFileTime/FS/class1.fs | 16 + .../DateTime.FromFileTime/FS/fs.fsproj | 9 + .../DateTime.GetDateTimeFormats/FS/class1.fs | 78 ++++ .../DateTime.GetDateTimeFormats/FS/fs.fsproj | 9 + .../DateTime.Kind_Suite/fs/fs.fsproj | 9 + .../DateTime.Kind_Suite/fs/ks.fs | 104 +++++ .../DateTime.Subtraction/FS/class1.fs | 24 + .../DateTime.Subtraction/FS/fs.fsproj | 9 + .../DateTime.ToFileTime/FS/class1.fs | 18 + .../DateTime.ToFileTime/FS/fs.fsproj | 9 + .../FS/class1.fs | 36 ++ .../FS/fs.fsproj | 9 + .../DateTime.ToShortLongString/fs/fs.fsproj | 9 + .../DateTime.ToShortLongString/fs/sls.fs | 43 ++ .../datetime.ctor_Int64/FS/fs.fsproj | 9 + .../datetime.ctor_Int64/FS/ticks.fs | 30 ++ .../FS/fs.fsproj | 9 + .../FS/source.fs | 46 ++ .../system.DateTime.AddHours/fs/AddHours1.fs | 30 ++ .../system.DateTime.AddHours/fs/fs.fsproj | 9 + .../system.DateTime.Date/fs/Date1.fs | 20 + .../system.DateTime.Date/fs/fs.fsproj | 9 + .../system.DateTime.Day/fs/Day1.fs | 22 + .../system.DateTime.Day/fs/Day2.fs | 29 ++ .../system.DateTime.Day/fs/fs.fsproj | 10 + .../fs/fs.fsproj | 9 + .../fs/sample.fs | 24 + .../system.DateTime.Hour/fs/Hour1.fs | 11 + .../system.DateTime.Hour/fs/fs.fsproj | 9 + .../fs/IsLeapYear1.fs | 23 + .../system.DateTime.IsLeapYear/fs/fs.fsproj | 9 + .../fs/Millisecond.fs | 22 + .../system.DateTime.Millisecond/fs/fs.fsproj | 9 + .../system.DateTime.MinValue/fs/MinValue.fs | 28 ++ .../system.DateTime.MinValue/fs/fs.fsproj | 9 + .../system.DateTime.Minute etc/FS/class1.fs | 27 ++ .../system.DateTime.Minute etc/FS/fs.fsproj | 9 + .../system.DateTime.Parse/fs/Parse1.fs | 52 +++ .../system.DateTime.Parse/fs/Parse2.fs | 19 + .../system.DateTime.Parse/fs/Parse3.fs | 46 ++ .../system.DateTime.Parse/fs/Parse4.fs | 65 +++ .../system.DateTime.Parse/fs/Parse4/fs.fsproj | 9 + .../system.DateTime.Parse/fs/Parse5.fs | 38 ++ .../system.DateTime.Parse/fs/Parse6.fs | 35 ++ .../system.DateTime.Parse/fs/fs.fsproj | 13 + .../fs/ParseExact1.fs | 77 ++++ .../system.DateTime.ParseExact/fs/fs.fsproj | 10 + .../fs/parseexact2.fs | 78 ++++ .../fs/parseexact2/fs.fsproj | 9 + .../fs/parseexact3.fs | 37 ++ .../system.DateTime.Ticks/fs/Ticks.fs | 25 ++ .../system.DateTime.Ticks/fs/fs.fsproj | 9 + .../fs/ToShortDateString.fs | 41 ++ .../fs/fs.fsproj | 9 + .../system.DateTime.ToString/fs/ToString1.fs | 29 ++ .../system.DateTime.ToString/fs/ToString2.fs | 48 ++ .../system.DateTime.ToString/fs/ToString4.fs | 34 ++ .../system.DateTime.ToString/fs/fs.fsproj | 13 + .../system.DateTime.ToString/fs/tostring3.fs | 103 +++++ .../system.DateTime.ToString/fs/tostring5.fs | 31 ++ .../system.DateTime.Today/fs/Today1.fs | 19 + .../system.DateTime.Today/fs/fs.fsproj | 9 + .../system.DateTime.TryParse/fs/TryParse1.fs | 33 ++ .../system.DateTime.TryParse/fs/fs.fsproj | 10 + .../system.DateTime.TryParse/fs/tryparse2.fs | 65 +++ .../fs/TryParseExact1.fs | 79 ++++ .../fs/TryParseExact2.fs | 32 ++ .../fs/fs.fsproj | 10 + .../system.DateTime.Year/fs/Year.fs | 21 + .../system.DateTime.Year/fs/fs.fsproj | 9 + .../fs/addmilliseconds2.fs | 24 + .../fs/fs.fsproj | 9 + .../fs/addminutes1.fs | 32 ++ .../system.datetime.addminutes/fs/fs.fsproj | 9 + .../fs/addmonths1.fs | 25 ++ .../system.datetime.addmonths/fs/fs.fsproj | 9 + .../fs/addseconds1.fs | 25 ++ .../system.datetime.addseconds/fs/fs.fsproj | 9 + .../system.datetime.addyears/fs/addyears1.fs | 51 +++ .../system.datetime.addyears/fs/fs.fsproj | 9 + .../system.datetime.compare/fs/compare1.fs | 20 + .../system.datetime.compare/fs/fs.fsproj | 9 + .../fs/ctorexample1.fs | 60 +++ .../fs/ctorexample2.fs | 51 +++ .../fs/ctorexample4.fs | 53 +++ .../fs/ctorexample6.fs | 53 +++ .../fs/ctorexample9.fs | 54 +++ .../system.datetime.constructor/fs/fs.fsproj | 13 + .../fs/dayofyear2.fs | 22 + .../system.datetime.dayofyear/fs/fs.fsproj | 9 + .../fs/daysinmonth3.fs | 46 ++ .../system.datetime.daysinmonth/fs/fs.fsproj | 9 + .../fs/frombinary1.fs | 15 + .../system.datetime.frombinary/fs/fs.fsproj | 9 + .../fs/fromfiletime1.fs | 14 + .../system.datetime.fromfiletime/fs/fs.fsproj | 9 + .../system.datetime.now/fs/fs.fsproj | 10 + .../system.datetime.now/fs/now1.fs | 21 + .../system.datetime.now/fs/now2.fs | 38 ++ .../system.datetime.timeofday/fs/fs.fsproj | 9 + .../fs/timeofday1.fs | 26 ++ .../system.datetime.tolocaltime/fs/fs.fsproj | 9 + .../fs/tolocaltime1.fs | 13 + .../fs/fs.fsproj | 9 + .../fs/sls.fs | 50 +++ ...e.tostring.argumentoutofrangeexception1.fs | 18 + ...e.tostring.argumentoutofrangeexception2.fs | 27 ++ ...e.tostring.argumentoutofrangeexception3.fs | 27 ++ ...e.tostring.argumentoutofrangeexception4.fs | 19 + .../fs/fs.fsproj | 12 + .../fs/fs.fsproj | 9 + .../fs/touniversaltime.fs | 16 + xml/System/DateTime.xml | 135 +++++- 138 files changed, 4013 insertions(+), 2 deletions(-) create mode 100644 samples/snippets/fsharp/System.DateTime/Calendar.fs create mode 100644 samples/snippets/fsharp/System.DateTime/DateTimeComparisons.fs create mode 100644 samples/snippets/fsharp/System.DateTime/DateWithTimeZone.fs create mode 100644 samples/snippets/fsharp/System.DateTime/Instantiation.fs create mode 100644 samples/snippets/fsharp/System.DateTime/Parsing.fs create mode 100644 samples/snippets/fsharp/System.DateTime/Persistence.fs create mode 100644 samples/snippets/fsharp/System.DateTime/Resolution.fs create mode 100644 samples/snippets/fsharp/System.DateTime/StringFormat.fs create mode 100644 samples/snippets/fsharp/System.DateTime/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/CompareTo_CS1_24564.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/dow.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/sls.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/ticks.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/source.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/AddHours1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/Date1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/sample.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/Hour1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/IsLeapYear1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse5.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse6.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/ParseExact1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/Ticks.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/ToShortDateString.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString4.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring5.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/Today1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/TryParse1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/tryparse2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/Year.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/addmilliseconds2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/addminutes1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/addmonths1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/addseconds1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/addyears1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/compare1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample4.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample6.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample9.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/dayofyear2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/daysinmonth3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/frombinary1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/timeofday1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/sls.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/fs.fsproj create mode 100644 samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs diff --git a/samples/snippets/fsharp/System.DateTime/Calendar.fs b/samples/snippets/fsharp/System.DateTime/Calendar.fs new file mode 100644 index 00000000000..34ad331aa26 --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/Calendar.fs @@ -0,0 +1,108 @@ +module Calender + +open System + +let thaiBuddistEra () = + // + let thTH = System.Globalization.CultureInfo "th-TH" + let value = DateTime(2016, 5, 28) + + printfn $"{value.ToString thTH}" + + thTH.DateTimeFormat.Calendar <- System.Globalization.GregorianCalendar() + + printfn $"{value.ToString thTH}" + + // The example displays the following output: + // 28/5/2559 0:00:00 + // 28/5/2016 0:00:00 + // + +let thaiBuddhistEraParse () = + // + let thTH = System.Globalization.CultureInfo "th-TH" + let value = DateTime.Parse("28/05/2559", thTH) + printfn $"{value.ToString thTH}" + + thTH.DateTimeFormat.Calendar <- System.Globalization.GregorianCalendar() + printfn $"{value.ToString thTH}" + + // The example displays the following output: + // 28/5/2559 0:00:00 + // 28/5/2016 0:00:00 + // + +let instantiateCalendar () = + // + let thTH = System.Globalization.CultureInfo "th-TH" + let dat = DateTime(2559, 5, 28, thTH.DateTimeFormat.Calendar) + + printfn $"""Thai Buddhist era date: {dat.ToString("d", thTH)}""" + printfn $"Gregorian date: {dat:d}" + + // The example displays the following output: + // Thai Buddhist Era Date: 28/5/2559 + // Gregorian Date: 28/05/2016 + // + +let calendarFields () = + // + let thTH = System.Globalization.CultureInfo "th-TH" + let cal = thTH.DateTimeFormat.Calendar + let dat = DateTime(2559, 5, 28, cal) + printfn "Using the Thai Buddhist Era calendar:" + printfn $"""Date: {dat.ToString("d", thTH)}""" + printfn $"Year: {cal.GetYear dat}" + printfn $"Leap year: {cal.IsLeapYear(cal.GetYear dat)}\n" + + printfn "Using the Gregorian calendar:" + printfn $"Date: {dat:d}" + printfn $"Year: {dat.Year}" + printfn $"Leap year: {DateTime.IsLeapYear dat.Year}" + + // The example displays the following output: + // Using the Thai Buddhist Era calendar + // Date : 28/5/2559 + // Year: 2559 + // Leap year : True + // + // Using the Gregorian calendar + // Date : 28/05/2016 + // Year: 2016 + // Leap year : True + // + +let calculateWeeks () = + // + let thTH = System.Globalization.CultureInfo "th-TH" + let thCalendar = thTH.DateTimeFormat.Calendar + let dat = DateTime(1395, 8, 18, thCalendar) + printfn "Using the Thai Buddhist Era calendar:" + printfn $"""Date: {dat.ToString("d", thTH)}""" + printfn $"Day of Week: {thCalendar.GetDayOfWeek dat}" + printfn $"Week of year: {thCalendar.GetWeekOfYear(dat, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday)}\n" + + let greg = System.Globalization.GregorianCalendar() + printfn "Using the Gregorian calendar:" + printfn $"Date: {dat:d}" + printfn $"Day of Week: {dat.DayOfWeek}" + printfn $"Week of year: {greg.GetWeekOfYear(dat, System.Globalization.CalendarWeekRule.FirstDay, DayOfWeek.Sunday)}" + + // The example displays the following output: + // Using the Thai Buddhist Era calendar + // Date : 18/8/1395 + // Day of Week: Sunday + // Week of year: 34 + // + // Using the Gregorian calendar + // Date : 18/08/0852 + // Day of Week: Sunday + // Week of year: 34 + // + + +thaiBuddistEra () +thaiBuddhistEraParse () +instantiateCalendar () +calendarFields () +calculateWeeks () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/DateTimeComparisons.fs b/samples/snippets/fsharp/System.DateTime/DateTimeComparisons.fs new file mode 100644 index 00000000000..0ad8d7bcc88 --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/DateTimeComparisons.fs @@ -0,0 +1,53 @@ +module DateTimeComparisons + +open System +open System.Text + +// +let roughlyEquals (time: DateTime) (timeWithWindow: DateTime) windowInSeconds frequencyInSeconds = + let delta = + int64 (timeWithWindow - time).TotalSeconds % frequencyInSeconds + + let delta = if delta > windowInSeconds then frequencyInSeconds - delta else delta + abs delta < windowInSeconds + +let testRoughlyEquals () = + let window = 10 + let window' = 10. + let freq = 60 * 60 * 2 // 2 hours + + let d1 = DateTime.Now + + let d2 = d1.AddSeconds(2. * window') + let d3 = d1.AddSeconds(-2. * window') + let d4 = d1.AddSeconds(window' / 2.) + let d5 = d1.AddSeconds(-window' / 2.) + + let d6 = (d1.AddHours 2).AddSeconds(2. * window') + let d7 = (d1.AddHours 2).AddSeconds(-2. * window') + let d8 = (d1.AddHours 2).AddSeconds(window' / 2.) + let d9 = (d1.AddHours 2).AddSeconds(-window' / 2.) + + printfn $"d1 ({d1}) ~= d1 ({d1}): {roughlyEquals d1 d1 window freq}" + printfn $"d1 ({d1}) ~= d2 ({d2}): {roughlyEquals d1 d2 window freq}" + printfn $"d1 ({d1}) ~= d3 ({d3}): {roughlyEquals d1 d3 window freq}" + printfn $"d1 ({d1}) ~= d4 ({d4}): {roughlyEquals d1 d4 window freq}" + printfn $"d1 ({d1}) ~= d5 ({d5}): {roughlyEquals d1 d5 window freq}" + + printfn $"d1 ({d1}) ~= d6 ({d6}): {roughlyEquals d1 d6 window freq}" + printfn $"d1 ({d1}) ~= d7 ({d7}): {roughlyEquals d1 d7 window freq}" + printfn $"d1 ({d1}) ~= d8 ({d8}): {roughlyEquals d1 d8 window freq}" + printfn $"d1 ({d1}) ~= d9 ({d9}): {roughlyEquals d1 d9 window freq}" + +// The example displays output similar to the following: +// d1 (1/28/2010 9:01:26 PM) ~= d1 (1/28/2010 9:01:26 PM): True +// d1 (1/28/2010 9:01:26 PM) ~= d2 (1/28/2010 9:01:46 PM): False +// d1 (1/28/2010 9:01:26 PM) ~= d3 (1/28/2010 9:01:06 PM): False +// d1 (1/28/2010 9:01:26 PM) ~= d4 (1/28/2010 9:01:31 PM): True +// d1 (1/28/2010 9:01:26 PM) ~= d5 (1/28/2010 9:01:21 PM): True +// d1 (1/28/2010 9:01:26 PM) ~= d6 (1/28/2010 11:01:46 PM): False +// d1 (1/28/2010 9:01:26 PM) ~= d7 (1/28/2010 11:01:06 PM): False +// d1 (1/28/2010 9:01:26 PM) ~= d8 (1/28/2010 11:01:31 PM): True +// d1 (1/28/2010 9:01:26 PM) ~= d9 (1/28/2010 11:01:21 PM): True +// +testRoughlyEquals () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/DateWithTimeZone.fs b/samples/snippets/fsharp/System.DateTime/DateWithTimeZone.fs new file mode 100644 index 00000000000..1545dc5c697 --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/DateWithTimeZone.fs @@ -0,0 +1,18 @@ +// +namespace DateTimeExtensions + +open System + +[] +type DateWithTimeZone = + struct + val TimeZone: TimeZoneInfo + val DateTime: DateTime + new (dateValue, timeZone) = + { DateTime = dateValue; + TimeZone = + if isNull timeZone then TimeZoneInfo.Local + else timeZone } + end + +// \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/Instantiation.fs b/samples/snippets/fsharp/System.DateTime/Instantiation.fs new file mode 100644 index 00000000000..b2414a9b60d --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/Instantiation.fs @@ -0,0 +1,42 @@ +module Instantiation + +open System + +let instantiateWithConstructor () = + // + let date1 = DateTime(2008, 5, 1, 8, 30, 52) + printfn $"{date1}" + // + +let instantiateWithReturnValue () = + // + let date1 = DateTime.Now + let date2 = DateTime.UtcNow + let date3 = DateTime.Today + // + () + +let instantiateFromString () = + // + let dateString = "5/1/2008 8:30:52 AM" + let date1 = DateTime.Parse(dateString, System.Globalization.CultureInfo.InvariantCulture) + let iso8601String = "20080501T08:30:52Z" + let dateISO8602 = DateTime.ParseExact(iso8601String, "yyyyMMddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture) + // + () + +let instantiateUsingDftCtor () = + // + let dat1 = DateTime() + + // The following method call displays 1/1/0001 12:00:00 AM. + printfn $"{dat1.ToString System.Globalization.CultureInfo.InvariantCulture}" + + // The following method call displays True. + printfn $"{dat1.Equals DateTime.MinValue}" + // + +instantiateWithConstructor () +instantiateWithReturnValue () +instantiateFromString () +instantiateUsingDftCtor () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/Parsing.fs b/samples/snippets/fsharp/System.DateTime/Parsing.fs new file mode 100644 index 00000000000..65ea361045d --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/Parsing.fs @@ -0,0 +1,64 @@ +module Parsing + +open System + +let parseStandardFormats () = + // + System.Threading.Thread.CurrentThread.CurrentCulture <- + System.Globalization.CultureInfo.CreateSpecificCulture "en-GB" + + let date1 = DateTime(2013, 6, 1, 12, 32, 30) + let badFormats = ResizeArray() + + printfn "%-37s %-19s\n" "Date String" "Date" + for dateString in date1.GetDateTimeFormats() do + match DateTime.TryParse dateString with + | true, parsedDate -> + printfn $"%-37s{dateString} %-19O{parsedDate}\n" + | _ -> + badFormats.Add dateString + + // Display strings that could not be parsed. + if badFormats.Count > 0 then + printfn "\nStrings that could not be parsed: " + for badFormat in badFormats do + printfn $" {badFormat}" + // Press "Run" to see the output. + // + +let parseCustomFormats () = + // + let formats = [| "yyyyMMdd"; "HHmmss" |] + let dateStrings = + [ "20130816"; "20131608"; " 20130816 " + "115216"; "521116"; " 115216 " ] + + for dateString in dateStrings do + match DateTime.TryParseExact(dateString, formats, null, + System.Globalization.DateTimeStyles.AllowWhiteSpaces ||| + System.Globalization.DateTimeStyles.AdjustToUniversal) with + | true, parsedDate -> + printfn $"{dateString} --> {parsedDate:g}" + | _ -> + printfn $"Cannot convert {dateString}" + + // The example displays the following output: + // 20130816 --> 8/16/2013 12:00 AM + // Cannot convert 20131608 + // 20130816 --> 8/16/2013 12:00 AM + // 115216 --> 4/22/2013 11:52 AM + // Cannot convert 521116 + // 115216 --> 4/22/2013 11:52 AM + // + +let parseISO8601 () = + // + let iso8601String = "20080501T08:30:52Z" + let dateISO8602 = DateTime.ParseExact(iso8601String, "yyyyMMddTHH:mm:ssZ", System.Globalization.CultureInfo.InvariantCulture) + + printfn $"{iso8601String} --> {dateISO8602:g}" + // + +parseStandardFormats () +parseCustomFormats () +parseISO8601 () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/Persistence.fs b/samples/snippets/fsharp/System.DateTime/Persistence.fs new file mode 100644 index 00000000000..336c3310570 --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/Persistence.fs @@ -0,0 +1,412 @@ +module Persistence + +open System +open System.Collections.Generic +open System.Globalization +open System.IO +open System.Runtime.Serialization +open System.Runtime.Serialization.Formatters.Binary +open System.Threading +open System.Xml.Serialization +open DateTimeExtensions + +let filenameTxt = @".\BadDates.txt" + +// +let saveLocalDatesAsString () = + let dates = + [ DateTime(2014, 6, 14, 6, 32, 0) + DateTime(2014, 7, 10, 23, 49, 0) + DateTime(2015, 1, 10, 1, 16, 0) + DateTime(2014, 12, 20, 21, 45, 0) + DateTime(2014, 6, 2, 15, 14, 0) ] + + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + let output = + [ for date in dates do + printfn $"{date}" + string date ] + |> String.concat "|" + + use sw = new StreamWriter(filenameTxt) + sw.Write output + printfn "Saved dates..." + +let restoreLocalDatesFromString () = + TimeZoneInfo.ClearCachedData() + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture "en-GB" + + use sr = new StreamReader(filenameTxt) + let inputValues = + sr.ReadToEnd().Split('|', StringSplitOptions.RemoveEmptyEntries) + + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + for inputValue in inputValues do + match DateTime.TryParse inputValue with + | true, dateValue -> + printfn $"'{inputValue}' --> {dateValue:f}" + | _ -> + printfn $"Cannot parse '{inputValue}'" + + printfn "Restored dates..." + +let persistAsLocalStrings () = + saveLocalDatesAsString () + restoreLocalDatesFromString () + +// When saved on an en-US system, the example displays the following output: +// Current Time Zone: (UTC-08:00) Pacific Time (US & Canada) +// The dates on an en-US system: +// Saturday, June 14, 2014 6:32 AM +// Thursday, July 10, 2014 11:49 PM +// Saturday, January 10, 2015 1:16 AM +// Saturday, December 20, 2014 9:45 PM +// Monday, June 02, 2014 3:14 PM +// Saved dates... +// +// When restored on an en-GB system, the example displays the following output: +// Current Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London +// The dates on an en-GB system: +// Cannot parse //6/14/2014 6:32:00 AM// +// //7/10/2014 11:49:00 PM// --> 07 October 2014 23:49 +// //1/10/2015 1:16:00 AM// --> 01 October 2015 01:16 +// Cannot parse //12/20/2014 9:45:00 PM// +// //6/2/2014 3:14:00 PM// --> 06 February 2014 15:14 +// Restored dates... +// + +// +let saveDatesAsInvariantStrings () = + let dates = + [ DateTime(2014, 6, 14, 6, 32, 0) + DateTime(2014, 7, 10, 23, 49, 0) + DateTime(2015, 1, 10, 1, 16, 0) + DateTime(2014, 12, 20, 21, 45, 0) + DateTime(2014, 6, 2, 15, 14, 0) ] + + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + let output = + [ for date in dates do + printfn $"{date:f}" + date.ToUniversalTime().ToString("O", CultureInfo.InvariantCulture) ] + |> String.concat "|" + + use sw = new StreamWriter(filenameTxt) + sw.Write output + printfn "Saved dates..." + +let restoreDatesAsInvariantStrings () = + TimeZoneInfo.ClearCachedData() + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture "en-GB" + + use sr = new StreamReader(filenameTxt) + let inputValues = + sr.ReadToEnd().Split('|', StringSplitOptions.RemoveEmptyEntries) + + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + for inputValue in inputValues do + match DateTime.TryParseExact(inputValue, "O", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind) with + | true, dateValue -> + printfn $"'{inputValue}' --> {dateValue.ToLocalTime():f}" + | _ -> + printfn $"Cannot parse '{inputValue}'" + + printfn "Restored dates..." + +let persistAsInvariantStrings () = + saveDatesAsInvariantStrings () + restoreDatesAsInvariantStrings () + +// When saved on an en-US system, the example displays the following output: +// Current Time Zone: (UTC-08:00) Pacific Time (US & Canada) +// The dates on an en-US system: +// Saturday, June 14, 2014 6:32 AM +// Thursday, July 10, 2014 11:49 PM +// Saturday, January 10, 2015 1:16 AM +// Saturday, December 20, 2014 9:45 PM +// Monday, June 02, 2014 3:14 PM +// Saved dates... +// +// When restored on an en-GB system, the example displays the following output: +// Current Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London +// The dates on an en-GB system: +// '2014-06-14T13:32:00.0000000Z' --> 14 June 2014 14:32 +// '2014-07-11T06:49:00.0000000Z' --> 11 July 2014 07:49 +// '2015-01-10T09:16:00.0000000Z' --> 10 January 2015 09:16 +// '2014-12-21T05:45:00.0000000Z' --> 21 December 2014 05:45 +// '2014-06-02T22:14:00.0000000Z' --> 02 June 2014 23:14 +// Restored dates... +// + +let filenameInts = @".\IntDates.bin" + +// +let saveDatesAsInts () = + let dates = + [ DateTime(2014, 6, 14, 6, 32, 0) + DateTime(2014, 7, 10, 23, 49, 0) + DateTime(2015, 1, 10, 1, 16, 0) + DateTime(2014, 12, 20, 21, 45, 0) + DateTime(2014, 6, 2, 15, 14, 0) ] + + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + let ticks = + [| for date in dates do + printfn $"{date:f}" + date.ToUniversalTime().Ticks |] + use fs = new FileStream(filenameInts, FileMode.Create) + use bw = new BinaryWriter(fs) + bw.Write ticks.Length + + for tick in ticks do + bw.Write tick + + printfn "Saved dates..." + +let restoreDatesAsInts () = + TimeZoneInfo.ClearCachedData() + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture "en-GB" + use fs = new FileStream(filenameInts, FileMode.Open) + use br = new BinaryReader(fs) + + try + let items = br.ReadInt32() + let dates = + [| for _ in 0..items do + let ticks = br.ReadInt64() + DateTime(ticks).ToLocalTime() |] + + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + for value in dates do + printfn $"{value:f}" + with + | :? EndOfStreamException -> + printfn "File corruption detected. Unable to restore data..." + | :? IOException -> + printfn "Unspecified I/O error. Unable to restore data..." + // Thrown during array initialization. + | :? OutOfMemoryException -> + printfn"File corruption detected. Unable to restore data..." + + printfn "Restored dates..." + +let persistAsIntegers () = + saveDatesAsInts () + restoreDatesAsInts () + +// When saved on an en-US system, the example displays the following output: +// Current Time Zone: (UTC-08:00) Pacific Time (US & Canada) +// The dates on an en-US system: +// Saturday, June 14, 2014 6:32 AM +// Thursday, July 10, 2014 11:49 PM +// Saturday, January 10, 2015 1:16 AM +// Saturday, December 20, 2014 9:45 PM +// Monday, June 02, 2014 3:14 PM +// Saved dates... +// +// When restored on an en-GB system, the example displays the following output: +// Current Time Zone: (UTC) Dublin, Edinburgh, Lisbon, London +// The dates on an en-GB system: +// 14 June 2014 14:32 +// 11 July 2014 07:49 +// 10 January 2015 09:16 +// 21 December 2014 05:45 +// 02 June 2014 23:14 +// Restored dates... +// + +let filenameXml = @".\LeapYears.xml" + +// +let persistAsXML () = + // Serialize the data. + let leapYears = + [| for year in 2000..4..2100 do + if DateTime.IsLeapYear year then + DateTime(year, 2, 29) |] + + let serializer = XmlSerializer(leapYears.GetType()) + use sw = new StreamWriter(filenameXml) + + try + serializer.Serialize(sw, leapYears) + with :? InvalidOperationException as e -> + printfn $"{e.InnerException.Message}" + + // Deserialize the data. + use fs = new FileStream(filenameXml, FileMode.Open) + + let deserializedDates = serializer.Deserialize fs :?> DateTime [] + + // Display the dates. + printfn $"Leap year days from 2000-2100 on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + let mutable nItems = 0 + for dat in deserializedDates do + printf $" {dat:d} " + nItems <- nItems + 1 + if nItems % 5 = 0 then + printfn "" + +// The example displays the following output: +// Leap year days from 2000-2100 on an en-GB system: +// 29/02/2000 29/02/2004 29/02/2008 29/02/2012 29/02/2016 +// 29/02/2020 29/02/2024 29/02/2028 29/02/2032 29/02/2036 +// 29/02/2040 29/02/2044 29/02/2048 29/02/2052 29/02/2056 +// 29/02/2060 29/02/2064 29/02/2068 29/02/2072 29/02/2076 +// 29/02/2080 29/02/2084 29/02/2088 29/02/2092 29/02/2096 +// + +let filenameBin = @".\Dates.bin" + +// +// BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information. + +let saveDatesBinary () = + let dates = + [| DateTime(2014, 6, 14, 6, 32, 0) + DateTime(2014, 7, 10, 23, 49, 0) + DateTime(2015, 1, 10, 1, 16, 0) + DateTime(2014, 12, 20, 21, 45, 0) + DateTime(2014, 6, 2, 15, 14, 0) |] + |> Array.map (fun date -> + printfn $"{date:f}" + date.ToUniversalTime() ) + + use fs = new FileStream(filenameBin, FileMode.Create) + let bin = BinaryFormatter() + + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + + bin.Serialize(fs, dates) + printfn "Saved dates..." + +let restoreDatesBinary () = + TimeZoneInfo.ClearCachedData() + printfn $"Current Time Zone: {TimeZoneInfo.Local.DisplayName}" + Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture "en-GB" + + use fs = new FileStream(filenameBin, FileMode.Open) + let bin = BinaryFormatter() + let dates = bin.Deserialize fs :?> DateTime [] + + printfn $"The dates on an {Thread.CurrentThread.CurrentCulture.Name} system:" + for value in dates do + printfn $"{value.ToLocalTime():f}" + + printfn "Restored dates..." + +let persistBinary () = + saveDatesBinary () + restoreDatesBinary () + +// When saved on an en-US system, the example displays the following output: +// Current Time Zone: (UTC-08:00) Pacific Time (US & Canada) +// The dates on an en-US system: +// Saturday, June 14, 2014 6:32 AM +// Thursday, July 10, 2014 11:49 PM +// Saturday, January 10, 2015 1:16 AM +// Saturday, December 20, 2014 9:45 PM +// Monday, June 02, 2014 3:14 PM +// Saved dates... +// +// When restored on an en-GB system, the example displays the following output: +// Current Time Zone: (UTC-6:00) Central Time (US & Canada) +// The dates on an en-GB system: +// 14 June 2014 08:32 +// 11 July 2014 01:49 +// 10 January 2015 03:16 +// 20 December 2014 23:45 +// 02 June 2014 17:14 +// Restored dates... +// + +// +// BinaryFormatter serialization is obsolete and should not be used. See https://aka.ms/binaryformatter for more information. + +let saveDateWithTimeZone () = + let dates = + [| DateWithTimeZone(DateTime(2014, 8, 9, 19, 30, 0), + TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time") + DateWithTimeZone(DateTime(2014, 8, 15, 19, 0, 0), + TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time") + DateWithTimeZone(DateTime(2014, 8, 22, 19, 30, 0), + TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time") + DateWithTimeZone(DateTime(2014, 8, 28, 19, 0, 0), + TimeZoneInfo.FindSystemTimeZoneById "Eastern Standard Time") |] + + use fs = new FileStream(@".\Schedule.bin", FileMode.Create) + let formatter = BinaryFormatter() + try + formatter.Serialize(fs, dates) + // Display dates. + for date in dates do + let tz = date.TimeZone + printfn $"{date.DateTime} {if tz.IsDaylightSavingTime date.DateTime then tz.DaylightName else tz.StandardName}" + with :? SerializationException as e -> + printfn $"Serialization failed. Reason: {e.Message}" + +// The example displays the following output: +// 8/9/2014 7:30:00 PM Eastern Daylight Time +// 8/15/2014 7:00:00 PM Pacific Daylight Time +// 8/22/2014 7:30:00 PM Eastern Daylight Time +// 8/28/2014 7:00:00 PM Eastern Daylight Time +// + +// +let restoreDateWithTimeZone () = + let filename = @".\Schedule.bin" + if File.Exists filename then + use fs = new FileStream(filename, FileMode.Open) + + let formatter = BinaryFormatter() + try + let dates = formatter.Deserialize fs :?> DateWithTimeZone [] + // Display dates. + for date in dates do + let tz = date.TimeZone + printfn $"{date.DateTime} {if tz.IsDaylightSavingTime date.DateTime then tz.DaylightName else tz.StandardName}" + with :? SerializationException as e -> + printfn $"Deserialization failed. Reason: {e.Message}" + else + printfn "Unable to find file to deserialize." + +// The example displays the following output: +// 8/9/2014 7:30:00 PM Eastern Daylight Time +// 8/15/2014 7:00:00 PM Pacific Daylight Time +// 8/22/2014 7:30:00 PM Eastern Daylight Time +// 8/28/2014 7:00:00 PM Eastern Daylight Time +// + + +File.Delete filenameTxt +persistAsLocalStrings () +File.Delete filenameTxt +persistAsInvariantStrings () +File.Delete filenameTxt + +File.Delete filenameInts +persistAsIntegers () +File.Delete filenameInts + +File.Delete filenameXml +persistAsXML () +File.Delete filenameXml + +File.Delete filenameBin +persistBinary () +File.Delete filenameBin + +saveDateWithTimeZone () +restoreDateWithTimeZone () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/Resolution.fs b/samples/snippets/fsharp/System.DateTime/Resolution.fs new file mode 100644 index 00000000000..0edf94059e0 --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/Resolution.fs @@ -0,0 +1,19 @@ +module Resolution + +open System + +let demonstrateResolution () = + // + let mutable output = "" + for i = 0 to 20 do + output <- output + $"{DateTime.Now.Millisecond}\n" + // Introduce a delay loop. + for _ = 0 to 1000 do () + + if i = 10 then + output <- output + "Thread.Sleep called...\n" + System.Threading.Thread.Sleep 5 + + printfn $"{output}" + // Press "Run" to see the output. + // \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/StringFormat.fs b/samples/snippets/fsharp/System.DateTime/StringFormat.fs new file mode 100644 index 00000000000..2378234057e --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/StringFormat.fs @@ -0,0 +1,44 @@ +module StringFormat + +open System + +let showDefaultToString () = + // + let date1 = DateTime(2008, 3, 1, 7, 0, 0) + printfn $"{date1.ToString()}" + // For en-US culture, displays 3/1/2008 7:00:00 AM + // + +let showCultureSpecificToString () = + // + let date1 = DateTime(2008, 3, 1, 7, 0, 0) + printfn $"""{date1.ToString(System.Globalization.CultureInfo.CreateSpecificCulture "fr-FR")}""" + // Displays 01/03/2008 07:00:00 + // + +let showDefaultFullDateAndTime () = + // + let date1 = DateTime(2008, 3, 1, 7, 0, 0) + printfn $"""{date1.ToString "F"}""" + // Displays Saturday, March 01, 2008 7:00:00 AM + // + +let showCultureSpecificFullDateAndTime () = + // + let date1 = DateTime(2008, 3, 1, 7, 0, 0) + printfn $"""{date1.ToString("F", new System.Globalization.CultureInfo "fr-FR")}""" + // Displays samedi 1 mars 2008 07:00:00 + // + +let showIso8601Format () = + // + let date1 = DateTime(2008, 3, 1, 7, 0, 0) + printfn $"""{date1.ToString "yyyyMMddTHH:mm:ssZ"}""" + // Displays 20080301T07:00:00Z + // + +showDefaultToString () +showCultureSpecificToString () +showDefaultFullDateAndTime () +showCultureSpecificFullDateAndTime () +showIso8601Format () \ No newline at end of file diff --git a/samples/snippets/fsharp/System.DateTime/fs.fsproj b/samples/snippets/fsharp/System.DateTime/fs.fsproj new file mode 100644 index 00000000000..ae1ec6b86af --- /dev/null +++ b/samples/snippets/fsharp/System.DateTime/fs.fsproj @@ -0,0 +1,16 @@ + + + Exe + net6.0 + + + + + + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs new file mode 100644 index 00000000000..0603a8034c8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs @@ -0,0 +1,31 @@ +open System + +[] +let main _ = + // Addition operator + // + let dTime = DateTime(1980, 8, 5) + + // tSpan is 17 days, 4 hours, 2 minutes and 1 second. + let tSpan = TimeSpan(17, 4, 2, 1) + + // Result gets 8/22/1980 4:02:01 AM. + let result = dTime + tSpan + // + + printfn $"{result}" + + // Equality operator. + // + let april19 = DateTime(2001, 4, 19) + let otherDate = DateTime(1991, 6, 5) + + // areEqual gets false. + let areEqual = april19 = otherDate + + let otherDate = DateTime(2001, 4, 19) + // areEqual gets true. + let areEqual = april19 = otherDate + // + + 0 \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime 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/DateTime.Add/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/class1.fs new file mode 100644 index 00000000000..806ddc058d7 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/class1.fs @@ -0,0 +1,9 @@ +open System + +// +// Calculate what day of the week is 36 days from this instant. +let today = DateTime.Now +let duration = TimeSpan(36, 0, 0, 0) +let answer = today.Add duration +printfn $"{answer:dddd}" +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/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/DateTime.AddDays/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/class1.fs new file mode 100644 index 00000000000..0a5c9bf0ff8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/class1.fs @@ -0,0 +1,13 @@ +// +open System + +let today = DateTime.Now +let answer = today.AddDays 36 +printfn $"Today: {today:dddd}" +printfn $"36 days from today: {answer:dddd}" + + +// The example displays output like the following: +// Today: Wednesday +// 36 days from today: Thursday +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/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/DateTime.CompareTo.2/FS/CompareTo_CS1_24564.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/CompareTo_CS1_24564.fs new file mode 100644 index 00000000000..722ba645158 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/CompareTo_CS1_24564.fs @@ -0,0 +1,31 @@ +// +open System + +type DateComparisonResult = + | Earlier = -1 + | Later = 1 + | TheSame = 0 + +[] +let main _ = + let thisDate = DateTime.Today + + // Define two DateTime objects for today's date next year and last year + // Call AddYears instance method to add/substract 1 year + let thisDateNextYear = thisDate.AddYears 1 + let thisDateLastYear = thisDate.AddYears -1 + + // Compare today to last year + let comparison = thisDate.CompareTo thisDateLastYear |> enum + printfn $"CompareTo method returns {int comparison}: {thisDate:d} is {comparison.ToString().ToLower()} than {thisDateLastYear:d}" + + // Compare today to next year + let comparison = thisDate.CompareTo thisDateNextYear |> enum + printfn $"CompareTo method returns {int comparison}: {thisDate:d} is {comparison.ToString().ToLower()} than {thisDateNextYear:d}" + + 0 + +// If run on December 31, 2021, the example produces the following output: +// CompareTo method returns 1: 12/31/2021 is later than 12/31/2020 +// CompareTo method returns -1: 12/31/2021 is earlier than 12/31/2022 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/fs.fsproj new file mode 100644 index 00000000000..b9c0d4dc622 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/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/DateTime.CompareTo/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/class1.fs new file mode 100644 index 00000000000..a9c556915a3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/class1.fs @@ -0,0 +1,19 @@ +// +open System + +let theDay = DateTime(DateTime.Today.Year, 7, 28) + +try + let compareValue = theDay.CompareTo DateTime.Today + + if compareValue < 0 then + printfn $"{theDay:d} is in the past." + elif compareValue = 0 then + printfn $"{theDay:d} is today!" + else // compareValue > 0 + printfn $"{theDay:d} has not come yet." + +with :? ArgumentException -> + Console.WriteLine("Value is not a DateTime"); + +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/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/DateTime.DayOfWeek/FS/dow.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/dow.fs new file mode 100644 index 00000000000..55eb96305bb --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/dow.fs @@ -0,0 +1,15 @@ +// +// This example demonstrates the DateTime.DayOfWeek property +open System + +// Assume the current culture is en-US. +// Create a DateTime for the first of May, 2003. +let dt = DateTime(2003, 5, 1) +printfn $"Is Thursday the day of the week for {dt:d}?: {dt.DayOfWeek = DayOfWeek.Thursday}" +printfn $"The day of the week for {dt:d} is {dt.DayOfWeek}." + +// This example produces the following results: +// +// Is Thursday the day of the week for 5/1/2003?: True +// The day of the week for 5/1/2003 is Thursday. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/fs.fsproj new file mode 100644 index 00000000000..4d75756e622 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/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/DateTime.DaysInMonth/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/class1.fs new file mode 100644 index 00000000000..a1b473cb1f3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/class1.fs @@ -0,0 +1,22 @@ +// +open System + +let July = 7 +let Feb = 2 + +let daysInJuly = DateTime.DaysInMonth(2001, July) +printfn $"{daysInJuly}" + +// daysInFeb gets 28 because the year 1998 was not a leap year. +let daysInFeb = DateTime.DaysInMonth(1998, Feb) +printfn $"{daysInFeb}" + +// daysInFebLeap gets 29 because the year 1996 was a leap year. +let daysInFebLeap = DateTime.DaysInMonth(1996, Feb) +printfn $"{daysInFebLeap}" + +// The example displays the following output: +// 31 +// 28 +// 29 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/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/DateTime.Equals/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/class1.fs new file mode 100644 index 00000000000..24cf2238058 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/class1.fs @@ -0,0 +1,20 @@ +// +let today1 = + System.DateTime System.DateTime.Today.Ticks + +let today2 = + System.DateTime System.DateTime.Today.Ticks + +let tomorrow = + System.DateTime.Today.AddDays(1).Ticks + |> System.DateTime + +// todayEqualsToday gets true. +let todayEqualsToday = System.DateTime.Equals(today1, today2) + +// todayEqualsTomorrow gets false. +let todayEqualsTomorrow = System.DateTime.Equals(today1, tomorrow) +// + +printfn $"{todayEqualsToday}" +printfn $"{todayEqualsTomorrow}" \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/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/DateTime.FromFileTime/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/class1.fs new file mode 100644 index 00000000000..3e68c7741a1 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/class1.fs @@ -0,0 +1,16 @@ + +// This function takes a file's creation time as an unsigned long, +// and returns its age. +// +open System + +let fileAge fileCreationTime = + let now = DateTime.Now + try + let fCreationTime = + DateTime.FromFileTime fileCreationTime + now.Subtract fCreationTime + with :? ArgumentOutOfRangeException -> + // fileCreationTime is not valid, so re-raise the exception. + reraise () +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.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/DateTime.GetDateTimeFormats/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs new file mode 100644 index 00000000000..fc9edc33f4c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs @@ -0,0 +1,78 @@ +open System + +let showDefaultFormats () = + // + let july28 = DateTime(2009, 7, 28, 5, 23, 15, 16) + + let july28Formats = july28.GetDateTimeFormats() + + // Print out july28 in all DateTime formats using the default culture. + for format in july28Formats do + printfn $"{format}" + // + +let showDefaultFrenchFormats () = + // + let july28 = DateTime(2009, 7, 28, 5, 23, 15, 16) + + let culture = + System.Globalization.CultureInfo("fr-FR", true) + + // Get the short date formats using the "fr-FR" culture. + let frenchJuly28Formats = + july28.GetDateTimeFormats culture + + // Display july28 in various formats using "fr-FR" culture. + for format in frenchJuly28Formats do + printfn $"{format}" + // + +let showDefaultDFormat () = + // + let july28 = DateTime(2009, 7, 28, 5, 23, 15) + + // Get the long date formats using the current culture. + let longJuly28Formats = + july28.GetDateTimeFormats 'D' + + // Display july28 in all long date formats. + for format in longJuly28Formats do + printfn $"{format}" + + // The example displays the following output: + // Tuesday, July 28, 2009 + // July 28, 2009 + // Tuesday, 28 July, 2009 + // 28 July, 2009 + // + +let showFrenchDFormat () = + // + let july28 = DateTime(2009, 7, 28, 5, 23, 15) + + let culture = + System.Globalization.CultureInfo("fr-FR", true) + + // Get the short date formats using the "fr-FR" culture. + let frenchJuly28Formats = + july28.GetDateTimeFormats('d', culture) + + // Display july28 in short date formats using "fr-FR" culture. + for format in frenchJuly28Formats do + printfn $"{format}" + + // The example displays the following output: + // 28/07/2009 + // 28/07/09 + // 28.07.09 + // 28-07-09 + // 2009-07-28 + // + + +showDefaultFormats () +showDefaultFrenchFormats () +printfn "\nDefault 'D' Format:\n" +showDefaultDFormat () +printfn "\nFrench 'D' Format:\n" +showFrenchDFormat () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/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/DateTime.Kind_Suite/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/fs.fsproj new file mode 100644 index 00000000000..0929dd132dc --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/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/DateTime.Kind_Suite/fs/ks.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs new file mode 100644 index 00000000000..b4320ca6d31 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs @@ -0,0 +1,104 @@ +// +// This code example demonstrates the DateTime Kind, Now, and +// UtcNow properties, and the SpecifyKind(), ToLocalTime(), +// and ToUniversalTime() methods. + +open System + +// Display the value and Kind property of a DateTime structure, the +// DateTime structure converted to local time, and the DateTime +// structure converted to universal time. + +let datePatt = @"M/d/yyyy hh:mm:ss tt" + +let display title (inputDt: DateTime) = + // Display the original DateTime. + + let dispDt = inputDt + let dtString = dispDt.ToString datePatt + printfn $"%s{title} {dtString}, Kind = {dispDt.Kind}" + + // Convert inputDt to local time and display the result. + // If inputDt.Kind is DateTimeKind.Utc, the conversion is performed. + // If inputDt.Kind is DateTimeKind.Local, the conversion is not performed. + // If inputDt.Kind is DateTimeKind.Unspecified, the conversion is + // performed as if inputDt was universal time. + + let dispDt = inputDt.ToLocalTime() + let dtString = dispDt.ToString datePatt + printfn $" ToLocalTime: {dtString}, Kind = {dispDt.Kind}" + + // Convert inputDt to universal time and display the result. + // If inputDt.Kind is DateTimeKind.Utc, the conversion is not performed. + // If inputDt.Kind is DateTimeKind.Local, the conversion is performed. + // If inputDt.Kind is DateTimeKind.Unspecified, the conversion is + // performed as if inputDt was local time. + + let dispDt = inputDt.ToUniversalTime() + let dtString = dispDt.ToString datePatt + printfn $" ToUniversalTime: {dtString}, Kind = {dispDt.Kind}\n" + + // Display the value and Kind property for DateTime.Now and DateTime.UtcNow. + +let displayNow title (inputDt: DateTime) = + let dtString = inputDt.ToString datePatt + printfn $"%s{title} {dtString}, Kind = {inputDt.Kind}" + +[] +let main _ = + + // Get the date and time for the current moment, adjusted + // to the local time zone. + + let saveNow = DateTime.Now + + // Get the date and time for the current moment expressed + // as coordinated universal time (UTC). + + let saveUtcNow = DateTime.UtcNow + + // Display the value and Kind property of the current moment + // expressed as UTC and local time. + + displayNow "UtcNow: .........." saveUtcNow + displayNow "Now: ............." saveNow + printfn "" + + // Change the Kind property of the current moment to + // DateTimeKind.Utc and display the result. + + let myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Utc) + display "Utc: ............." myDt + + // Change the Kind property of the current moment to + // DateTimeKind.Local and display the result. + + let myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Local) + display "Local: ..........." myDt + + // Change the Kind property of the current moment to + // DateTimeKind.Unspecified and display the result. + + let myDt = DateTime.SpecifyKind(saveNow, DateTimeKind.Unspecified) + display "Unspecified: ....." myDt + + 0 + + +// This code example produces the following results: +// +// UtcNow: .......... 5/6/2005 09:34:42 PM, Kind = Utc +// Now: ............. 5/6/2005 02:34:42 PM, Kind = Local +// +// Utc: ............. 5/6/2005 02:34:42 PM, Kind = Utc +// ToLocalTime: 5/6/2005 07:34:42 AM, Kind = Local +// ToUniversalTime: 5/6/2005 02:34:42 PM, Kind = Utc +// +// Local: ........... 5/6/2005 02:34:42 PM, Kind = Local +// ToLocalTime: 5/6/2005 02:34:42 PM, Kind = Local +// ToUniversalTime: 5/6/2005 09:34:42 PM, Kind = Utc +// +// Unspecified: ..... 5/6/2005 02:34:42 PM, Kind = Unspecified +// ToLocalTime: 5/6/2005 07:34:42 AM, Kind = Local +// ToUniversalTime: 5/6/2005 09:34:42 PM, Kind = Utc +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs new file mode 100644 index 00000000000..a7f05887a80 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs @@ -0,0 +1,24 @@ +// +open System + +let date1 = DateTime(1996, 6, 3, 22, 15, 0) +let date2 = DateTime(1996, 12, 6, 13, 2, 0) +let date3 = DateTime(1996, 10, 12, 8, 42, 0) + +// diff1 gets 185 days, 14 hours, and 47 minutes. +let diff1 = date2.Subtract date1 + +// date4 gets 4/9/1996 5:55:00 PM. +let date4 = date3.Subtract diff1 + +// diff2 gets 55 days 4 hours and 20 minutes. +let diff2 = date2 - date3 + +// date5 gets 4/9/1996 5:55:00 PM. +let date5 = date1 - diff2 +// + +System.Console.WriteLine(diff1) +System.Console.WriteLine(date4) +System.Console.WriteLine(diff2) +System.Console.WriteLine(date4) \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/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/DateTime.ToFileTime/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/class1.fs new file mode 100644 index 00000000000..3c7b2d9a2c6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/class1.fs @@ -0,0 +1,18 @@ +// +open System.IO + +printfn "Enter the file path:" +let filePath = stdin.ReadLine() + +if File.Exists filePath then + let fileCreationDateTime = + File.GetCreationTime filePath + + let fileCreationFileTime = fileCreationDateTime.ToFileTime() + + printfn $"{fileCreationDateTime} in file time is {fileCreationFileTime}." + +else + printfn $"{filePath} is an invalid file" + +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/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/DateTime.ToLocalTime ToUniversalTime/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/class1.fs new file mode 100644 index 00000000000..9fb5563a8a3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/class1.fs @@ -0,0 +1,36 @@ +// +open System + +printfn "Enter a date and time." + +try + let strDateTime = stdin.ReadLine() + let localDateTime = DateTime.Parse strDateTime + let univDateTime = localDateTime.ToUniversalTime() + + printfn $"{localDateTime} local time is {univDateTime} universal time." + +with :? FormatException -> + printfn "Invalid format." + +printfn "Enter a date and time in universal time." + +try + let strDateTime = stdin.ReadLine() + let univDateTime = DateTime.Parse strDateTime + let localDateTime = univDateTime.ToLocalTime() + + printfn $"{univDateTime} universal time is {localDateTime} local time." + +with :? FormatException -> + printfn "Invalid format." + +// The example displays output like the following when run on a +// computer whose culture is en-US in the Pacific Standard Time zone: +// Enter a date and time. +// 12/10/2015 6:18 AM +// 12/10/2015 6:18:00 AM local time is 12/10/2015 2:18:00 PM universal time. +// Enter a date and time in universal time. +// 12/20/2015 6:42:00 +// 12/20/2015 6:42:00 AM universal time is 12/19/2015 10:42:00 PM local time. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/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/DateTime.ToShortLongString/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/fs.fsproj new file mode 100644 index 00000000000..c6a16948727 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/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/DateTime.ToShortLongString/fs/sls.fs b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/sls.fs new file mode 100644 index 00000000000..f42d1ae0b2e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/sls.fs @@ -0,0 +1,43 @@ +// +open System +open System.Globalization + +// Initialize a DateTime object. +printfn "Initialize the DateTime object to May 16, 2001 3:02:15 AM.\n" +let dateAndTime = DateTime(2001, 5, 16, 3, 2, 15) + +// Display the name of the current culture. +printfn $"Current culture: \"{CultureInfo.CurrentCulture.Name}\"\n" +let dtfi = CultureInfo.CurrentCulture.DateTimeFormat + +// Display the long date pattern and string. +printfn $"Long date pattern: \"{dtfi.LongDatePattern}\"" +printfn $"Long date string: \"{dateAndTime.ToLongDateString()}\"\n" + +// Display the long time pattern and string. +printfn $"Long time pattern: \"{dtfi.LongTimePattern}\"" +printfn $"Long time string: \"{dateAndTime.ToLongTimeString()}\"\n" + +// Display the short date pattern and string. +printfn $"Short date pattern: \"{dtfi.ShortDatePattern}\"" +printfn $"Short date string: \"{dateAndTime.ToShortDateString()}\"\n" + +// Display the short time pattern and string. +printfn $"Short time pattern: \"{dtfi.ShortTimePattern}\"" +printfn $"Short time string: \"{dateAndTime.ToShortTimeString()}\"\n" + +// The example displays output similar to the following: +// Current culture: "en-US" +// +// Long date pattern: "dddd, MMMM d, yyyy" +// Long date string: "Wednesday, May 16, 2001" +// +// Long time pattern: "h:mm:ss tt" +// Long time string: "3:02:15 AM" +// +// Short date pattern: "M/d/yyyy" +// Short date string: "5/16/2001" +// +// Short time pattern: "h:mm tt" +// Short time string: "3:02 AM" +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/fs.fsproj new file mode 100644 index 00000000000..1f8288b4a36 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/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/datetime.ctor_Int64/FS/ticks.fs b/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/ticks.fs new file mode 100644 index 00000000000..29c72c9432e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/ticks.fs @@ -0,0 +1,30 @@ +// +// This example demonstrates the DateTime(Int64) constructor. +open System +open System.Globalization + +// Create a DateTime for the maximum date and time using ticks. +let dt1 = DateTime DateTime.MaxValue.Ticks + +// Create a DateTime for the minimum date and time using ticks. +let dt2 = DateTime DateTime.MinValue.Ticks + +// Create a custom DateTime for 7/28/1979 at 10:35:05 PM using a +// calendar based on the "en-US" culture, and ticks. +let ticks = DateTime(1979, 07, 28, 22, 35, 5, CultureInfo("en-US", false).Calendar).Ticks +let dt3 = DateTime ticks + +printfn $"""1) The maximum date and time is {dt1.ToString "MM-dd/yyyy hh:mm:ss tt"}""" +printfn $"""2) The minimum date and time is {dt2.ToString "MM/dd/yyyy hh:mm:ss tt"}""" +printfn $"""3) The custom date and time is {dt3.ToString "MM/dd/yyyy hh:mm:ss tt"}""" + +printfn $"\nThe custom date and time is created from {ticks:N0} ticks." + +// This example produces the following results: +// +// 1) The maximum date and time is 12/31/9999 11:59:59 PM +// 2) The minimum date and time is 01/01/0001 12:00:00 AM +// 3) The custom date and time is 07/28/1979 10:35:05 PM +// +// The custom date and time is created from 624,376,461,050,000,000 ticks. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/fs.fsproj new file mode 100644 index 00000000000..fbff4133403 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/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_Classic/classic DateTime.ToString2 Example/FS/source.fs b/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/source.fs new file mode 100644 index 00000000000..d8a83629eda --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/source.fs @@ -0,0 +1,46 @@ +// +open System +open System.Globalization + +let dt = DateTime.Now +let formats = + [ "d"; "D" + "f"; "F" + "g"; "G" + "m" + "r" + "s" + "t"; "T" + "u"; "U" + "y" + "dddd, MMMM dd yyyy" + "ddd, MMM d \"'\"yy" + "dddd, MMMM dd" + "M/yy" + "dd-MM-yy" ] + +for format in formats do + let date = dt.ToString(format, DateTimeFormatInfo.InvariantInfo) + printfn $"{format}: {date}" + +// Output. +// d: 08/17/2000 +// D: Thursday, August 17, 2000 +// f: Thursday, August 17, 2000 16:32 +// F: Thursday, August 17, 2000 16:32:32 +// g: 08/17/2000 16:32 +// G: 08/17/2000 16:32:32 +// m: August 17 +// r: Thu, 17 Aug 2000 23:32:32 GMT +// s: 2000-08-17T16:32:32 +// t: 16:32 +// T: 16:32:32 +// u: 2000-08-17 23:32:32Z +// U: Thursday, August 17, 2000 23:32:32 +// y: August, 2000 +// dddd, MMMM dd yyyy: Thursday, August 17 2000 +// ddd, MMM d "'"yy: Thu, Aug 17 '00 +// dddd, MMMM dd: Thursday, August 17 +// M/yy: 8/00 +// dd-MM-yy: 17-08-00 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/AddHours1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/AddHours1.fs new file mode 100644 index 00000000000..e3f14ddf999 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/AddHours1.fs @@ -0,0 +1,30 @@ +// +open System + +let hours = + [ 0.08333; 0.16667; 0.25 + 0.33333; 0.5; 0.66667; 1 + 2; 29; 30; 31; 90; 365 ] + +let dateValue = DateTime(2009, 3, 1, 12, 0, 0) + +for hour in hours do + printfn $"{dateValue} + {hour} hour(s) = {dateValue.AddHours hour}" + + +// The example displays the following output on a system whose current +// culture is en-US: +// 3/1/2009 12:00:00 PM + 0.08333 hour(s) = 3/1/2009 12:04:59 PM +// 3/1/2009 12:00:00 PM + 0.16667 hour(s) = 3/1/2009 12:10:00 PM +// 3/1/2009 12:00:00 PM + 0.25 hour(s) = 3/1/2009 12:15:00 PM +// 3/1/2009 12:00:00 PM + 0.33333 hour(s) = 3/1/2009 12:19:59 PM +// 3/1/2009 12:00:00 PM + 0.5 hour(s) = 3/1/2009 12:30:00 PM +// 3/1/2009 12:00:00 PM + 0.66667 hour(s) = 3/1/2009 12:40:00 PM +// 3/1/2009 12:00:00 PM + 1 hour(s) = 3/1/2009 1:00:00 PM +// 3/1/2009 12:00:00 PM + 2 hour(s) = 3/1/2009 2:00:00 PM +// 3/1/2009 12:00:00 PM + 29 hour(s) = 3/2/2009 5:00:00 PM +// 3/1/2009 12:00:00 PM + 30 hour(s) = 3/2/2009 6:00:00 PM +// 3/1/2009 12:00:00 PM + 31 hour(s) = 3/2/2009 7:00:00 PM +// 3/1/2009 12:00:00 PM + 90 hour(s) = 3/5/2009 6:00:00 AM +// 3/1/2009 12:00:00 PM + 365 hour(s) = 3/16/2009 5:00:00 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/fs.fsproj new file mode 100644 index 00000000000..60b0f1f519a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/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.DateTime.Date/fs/Date1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/Date1.fs new file mode 100644 index 00000000000..b842886f111 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/Date1.fs @@ -0,0 +1,20 @@ +// +open System + +let date1 = DateTime(2008, 6, 1, 7, 47, 0) +printfn $"{date1}" + +// Get date-only portion of date, without its time. +let dateOnly = date1.Date +// Display date using short date string. +printfn $"{dateOnly:d}" +// Display date using 24-hour clock. +printfn $"{dateOnly:g}" +printfn $"""{dateOnly.ToString "MM/dd/yyyy HH:mm"}""" + +// The example displays output like the following output: +// 6/1/2008 7:47:00 AM +// 6/1/2008 +// 6/1/2008 12:00 AM +// 06/01/2008 00:00 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/fs.fsproj new file mode 100644 index 00000000000..2570750f9b5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/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.DateTime.Day/fs/Day1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day1.fs new file mode 100644 index 00000000000..3925271829f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day1.fs @@ -0,0 +1,22 @@ +module Day1 + +open System +open System.Globalization + +// +// Return day of 1/13/2009. +let dateGregorian = DateTime(2009, 1, 13) +printfn $"{dateGregorian.Day}" +// Displays 13 (Gregorian day). + +// Create date of 1/13/2009 using Hijri calendar. +let hijri = HijriCalendar() +let dateHijri = DateTime(1430, 1, 17, hijri) +// Return day of date created using Hijri calendar. +printfn $"{dateHijri.Day}" +// Displays 13 (Gregorian day). + +// Display day of date in Hijri calendar. +printfn $"{hijri.GetDayOfMonth dateHijri}" +// Displays 17 (Hijri day). +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day2.fs new file mode 100644 index 00000000000..6dd11ff6fba --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day2.fs @@ -0,0 +1,29 @@ +module Day2 + +// +open System +open System.Globalization +open System.Threading + +let originalCulture = Thread.CurrentThread.CurrentCulture + +// Change current culture to ar-SA. +let ci = CultureInfo "ar-SA" +Thread.CurrentThread.CurrentCulture <- ci + +let hijriDate = new DateTime(1430, 1, 17, + Thread.CurrentThread.CurrentCulture.Calendar); +// Display date (uses calendar of current culture by default). +printfn $"""{hijriDate.ToString "dd-MM-yyyy"}""" +// Displays 17-01-1430. + +// Display day of 17th of Muharram +printfn $"{hijriDate.Day}" +// Displays 13 (corresponding day of January in Gregorian calendar). + +// Display day of 17th of Muharram in Hijri calendar. +printfn $"{Thread.CurrentThread.CurrentCulture.Calendar.GetDayOfMonth hijriDate}" +// Displays 17. + +Thread.CurrentThread.CurrentCulture <- originalCulture +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/fs.fsproj new file mode 100644 index 00000000000..da36416e70b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/fs.fsproj new file mode 100644 index 00000000000..834c5732492 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/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.DateTime.Equals-Instance/fs/sample.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/sample.fs new file mode 100644 index 00000000000..035a37d324f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/sample.fs @@ -0,0 +1,24 @@ +// +open System + +// Create some DateTime objects. +let one = DateTime.UtcNow + +let two = DateTime.Now + +let three = one + +// Compare the DateTime objects and display the results. +let result = one.Equals two + +printfn $"The result of comparing DateTime object one and two is: {result}." + +let result2 = one.Equals three + +printfn $"The result of comparing DateTime object one and three is: {result2}." + +// This code example displays the following: +// +// The result of comparing DateTime object one and two is: False. +// The result of comparing DateTime object one and three is: True. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/Hour1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/Hour1.fs new file mode 100644 index 00000000000..911e12e8d32 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/Hour1.fs @@ -0,0 +1,11 @@ +open System + +// +let date1 = DateTime(2008, 4, 1, 18, 53, 0) + +date1.ToString "%h" +|> printfn "%s" // Displays 6 + +date1.ToString "h tt" +|> printfn "%s" // Displays 6 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/fs.fsproj new file mode 100644 index 00000000000..81382761394 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/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.DateTime.IsLeapYear/fs/IsLeapYear1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/IsLeapYear1.fs new file mode 100644 index 00000000000..8ec66f77a8c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/IsLeapYear1.fs @@ -0,0 +1,23 @@ +// +open System + +[ 1994..2014 ] +|> List.filter DateTime.IsLeapYear +|> List.iter (fun year -> + printfn $"{year} is a leap year." + let leapDay = DateTime(year, 2, 29) + let nextYear = leapDay.AddYears 1 + printfn $" One year from {leapDay:d} is {nextYear:d}.") + +// The example produces the following output: +// 1996 is a leap year. +// One year from 2/29/1996 is 2/28/1997. +// 2000 is a leap year. +// One year from 2/29/2000 is 2/28/2001. +// 2004 is a leap year. +// One year from 2/29/2004 is 2/28/2005. +// 2008 is a leap year. +// One year from 2/29/2008 is 2/28/2009. +// 2012 is a leap year. +// One year from 2/29/2012 is 2/28/2013. +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/fs.fsproj new file mode 100644 index 00000000000..57de251bd31 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/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.DateTime.Millisecond/fs/Millisecond.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs new file mode 100644 index 00000000000..8c067b2746d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs @@ -0,0 +1,22 @@ +open System + +// +let date1 = DateTime(2008, 1, 1, 0, 30, 45, 125) +printfn $"Milliseconds: {date1:fff}" // displays Milliseconds: 125 +// + +// +let date2 = DateTime(2008, 1, 1, 0, 30, 45, 125) +printfn $"Date: {date2:o}" + +// Displays the following output to the console: +// Date: 2008-01-01T00:30:45.1250000 +// + +// +let date3 = DateTime(2008, 1, 1, 0, 30, 45, 125) +printfn $"""Date with milliseconds: {date3.ToString "MM/dd/yyy HH:mm:ss.fff"}""" + +// Displays the following output to the console: +// Date with milliseconds: 01/01/2008 00:30:45.125 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/fs.fsproj new file mode 100644 index 00000000000..38a3cbf113c --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/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.DateTime.MinValue/fs/MinValue.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs new file mode 100644 index 00000000000..a5b4625b060 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs @@ -0,0 +1,28 @@ +open System + +// +// Define an uninitialized date. +let date1 = DateTime() +printf $"{date1}" +if date1.Equals DateTime.MinValue then + printfn $" (Equals Date.MinValue)" +// The example displays the following output: +// 1/1/0001 12:00:00 AM (Equals Date.MinValue) +// + +// +// Attempt to assign an out-of-range value to a DateTime constructor. +let numberOfTicks = Int64.MaxValue + +// Validate the value. +if numberOfTicks >= DateTime.MinValue.Ticks && + numberOfTicks <= DateTime.MaxValue.Ticks then + let validDate = DateTime numberOfTicks + () +elif numberOfTicks < DateTime.MinValue.Ticks then + printfn $"{numberOfTicks:N0} is less than {DateTime.MinValue.Ticks:N0} ticks." +else + printfn $"{numberOfTicks:N0} is greater than {DateTime.MaxValue.Ticks:N0} ticks." +// The example displays the following output: +// 9,223,372,036,854,775,807 is greater than 3,155,378,975,999,999,999 ticks. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/fs.fsproj new file mode 100644 index 00000000000..8a32572e8d4 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/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.DateTime.Minute etc/FS/class1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs new file mode 100644 index 00000000000..82d83462a3d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs @@ -0,0 +1,27 @@ +// +open System + + +let moment = System.DateTime(1999, 1, 13, 3, 57, 32, 11) + +// Year gets 1999. +let year = moment.Year + +// Month gets 1 (January). +let month = moment.Month + +// Day gets 13. +let day = moment.Day + +// Hour gets 3. +let hour = moment.Hour + +// Minute gets 57. +let minute = moment.Minute + +// Second gets 32. +let second = moment.Second + +// Millisecond gets 11. +let millisecond = moment.Millisecond +// diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/fs.fsproj new file mode 100644 index 00000000000..0d4b6596c65 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/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.DateTime.Parse/fs/Parse1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse1.fs new file mode 100644 index 00000000000..609ba4bd9cd --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse1.fs @@ -0,0 +1,52 @@ +module Parse1 + +// +open System +open System.Globalization + +[] +let main _ = + // Assume the current culture is en-US. + // The date is February 16, 2008, 12 hours, 15 minutes and 12 seconds. + + // Use standard en-US date and time value + let dateString = "2/16/2008 12:15:12 PM" + try + let dateValue = DateTime.Parse dateString + printfn $"'{dateString}' converted to {dateValue}." + with :? FormatException -> + printfn $"Unable to convert '{dateString}'." + + // Reverse month and day to conform to the fr-FR culture. + // The date is February 16, 2008, 12 hours, 15 minutes and 12 seconds. + let dateString = "16/02/2008 12:15:12" + try + let dateValue = DateTime.Parse dateString + printfn $"'{dateString}' converted to {dateValue}." + with :? FormatException -> + Console.WriteLine("Unable to convert '{0}'.", dateString) + + // Call another overload of Parse to successfully convert string + // formatted according to conventions of fr-FR culture. + try + let dateValue = DateTime.Parse(dateString, CultureInfo("fr-FR", false)) + printfn $"'{dateString}' converted to {dateValue}." + with :? FormatException -> + printfn $"Unable to convert '{dateString}'." + + // Parse string with date but no time component. + let dateString = "2/16/2008" + try + let dateValue = DateTime.Parse dateString + printfn $"'{dateString}' converted to {dateValue}." + with :? FormatException -> + printfn $"Unable to convert '{dateString}'." + + 0 + +// The example displays the following output to the console: +// '2/16/2008 12:15:12 PM' converted to 2/16/2008 12:15:12 PM. +// Unable to convert '16/02/2008 12:15:12'. +// '16/02/2008 12:15:12' converted to 2/16/2008 12:15:12 PM. +// '2/16/2008' converted to 2/16/2008 12:00:00 AM. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse2.fs new file mode 100644 index 00000000000..d269c49158f --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse2.fs @@ -0,0 +1,19 @@ +module Parse2 + +// +open System + +let dateStrings = + [ "2008-05-01T07:34:42-5:00" + "2008-05-01 7:34:42Z" + "Thu, 01 May 2008 07:34:42 GMT" ] + +for dateString in dateStrings do + let convertedDate = DateTime.Parse dateString + printfn $"Converted {dateString} to {convertedDate.Kind} time {convertedDate}" + +// These calls to the DateTime.Parse method display the following output: +// Converted 2008-05-01T07:34:42-5:00 to Local time 5/1/2008 5:34:42 AM +// Converted 2008-05-01 7:34:42Z to Local time 5/1/2008 12:34:42 AM +// Converted Thu, 01 May 2008 07:34:42 GMT to Local time 5/1/2008 12:34:42 AM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse3.fs new file mode 100644 index 00000000000..76374ba980a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse3.fs @@ -0,0 +1,46 @@ +module Parse3 + +// +open System +open System.Globalization + +// Define cultures to be used to parse dates. +let cultures = + [ CultureInfo.CreateSpecificCulture "en-US" + CultureInfo.CreateSpecificCulture "fr-FR" + CultureInfo.CreateSpecificCulture "de-DE" ] + +// Define string representations of a date to be parsed. +let dateStrings = + [ "01/10/2009 7:34 PM" + "10.01.2009 19:34" + "10-1-2009 19:34" ] + +// Parse dates using each culture. +for culture in cultures do + printfn $"Attempted conversions using {culture.Name} culture." + for dateString in dateStrings do + try + let dateValue = DateTime.Parse(dateString, culture) + printfn $""" Converted '{dateString}' to {dateValue.ToString("f", culture)}.""" + with :? FormatException -> + printfn $" Unable to convert '{dateString}' for culture {culture.Name}." + printfn "" + + +// The example displays the following output to the console: +// Attempted conversions using en-US culture. +// Converted '01/10/2009 7:34 PM' to Saturday, January 10, 2009 7:34 PM. +// Converted '10.01.2009 19:34' to Thursday, October 01, 2009 7:34 PM. +// Converted '10-1-2009 19:34' to Thursday, October 01, 2009 7:34 PM. +// +// Attempted conversions using fr-FR culture. +// Converted '01/10/2009 7:34 PM' to jeudi 1 octobre 2009 19:34. +// Converted '10.01.2009 19:34' to samedi 10 janvier 2009 19:34. +// Converted '10-1-2009 19:34' to samedi 10 janvier 2009 19:34. +// +// Attempted conversions using de-DE culture. +// Converted '01/10/2009 7:34 PM' to Donnerstag, 1. Oktober 2009 19:34. +// Converted '10.01.2009 19:34' to Samstag, 10. Januar 2009 19:34. +// Converted '10-1-2009 19:34' to Samstag, 10. Januar 2009 19:34. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4.fs new file mode 100644 index 00000000000..4bcc87243d4 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4.fs @@ -0,0 +1,65 @@ +module Parse4 + +// +open System +open System.Globalization + +[] +let main _ = + // Parse a date and time with no styles. + let dateString = "03/01/2009 10:00 AM" + let culture = CultureInfo.CreateSpecificCulture "en-US" + let styles = DateTimeStyles.None + try + let result = DateTime.Parse(dateString, culture, styles) + printfn $"{dateString} converted to {result} {result.Kind}." + with :? FormatException -> + printfn $"Unable to convert {dateString} to a date and time." + + // Parse the same date and time with the AssumeLocal style. + let styles = DateTimeStyles.AssumeLocal + try + let result = DateTime.Parse(dateString, culture, styles) + printfn $"{dateString} converted to {result} {result.Kind}." + with :? FormatException -> + printfn $"Unable to convert {dateString} to a date and time." + + // Parse a date and time that is assumed to be local. + // This time is five hours behind UTC. The local system's time zone is + // eight hours behind UTC. + let dateString = "2009/03/01T10:00:00-5:00" + let styles = DateTimeStyles.AssumeLocal + try + let result = DateTime.Parse(dateString, culture, styles) + printfn $"{dateString} converted to {result} {result.Kind}." + with :? FormatException -> + printfn $"Unable to convert {dateString} to a date and time." + + // Attempt to convert a string in improper ISO 8601 format. + let dateString = "03/01/2009T10:00:00-5:00" + try + let result = DateTime.Parse(dateString, culture, styles) + printfn $"{dateString} converted to {result} {result.Kind}." + with :? FormatException -> + printfn $"Unable to convert {dateString} to a date and time." + + // Assume a date and time string formatted for the fr-FR culture is the local + // time and convert it to UTC. + let dateString = "2008-03-01 10:00" + let culture = CultureInfo.CreateSpecificCulture "fr-FR" + let styles = DateTimeStyles.AdjustToUniversal ||| DateTimeStyles.AssumeLocal + try + let result = DateTime.Parse(dateString, culture, styles) + printfn $"{dateString} converted to {result} {result.Kind}." + with :? FormatException -> + printfn $"Unable to convert {dateString} to a date and time." + + 0 + +// The example displays the following output to the console: +// 03/01/2009 10:00 AM converted to 3/1/2009 10:00:00 AM Unspecified. +// 03/01/2009 10:00 AM converted to 3/1/2009 10:00:00 AM Local. +// 2009/03/01T10:00:00-5:00 converted to 3/1/2009 7:00:00 AM Local. +// Unable to convert 03/01/2009T10:00:00-5:00 to a date and time. +// 2008-03-01 10:00 converted to 3/1/2008 6:00:00 PM Utc. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4/fs.fsproj new file mode 100644 index 00000000000..66b738034c1 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4/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.DateTime.Parse/fs/Parse5.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse5.fs new file mode 100644 index 00000000000..b89f8dca590 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse5.fs @@ -0,0 +1,38 @@ +module Parse5 + +open System +open System.Globalization + +// +let formattedDates = + [ "2008-09-15T09:30:41.7752486-07:00" + "2008-09-15T09:30:41.7752486Z" + "2008-09-15T09:30:41.7752486" + "2008-09-15T09:30:41.7752486-04:00" + "Mon, 15 Sep 2008 09:30:41 GMT" ] + +for formattedDate in formattedDates do + printfn $"{formattedDate}" + let roundtripDate = DateTime.Parse(formattedDate, null, DateTimeStyles.RoundtripKind) + printfn $" With RoundtripKind flag: {roundtripDate} {roundtripDate.Kind} time." + + let noRoundtripDate = DateTime.Parse(formattedDate, null, DateTimeStyles.None) + printfn $" Without RoundtripKind flag: {noRoundtripDate} {noRoundtripDate.Kind} time." + +// The example displays the following output: +// 2008-09-15T09:30:41.7752486-07:00 +// With RoundtripKind flag: 9/15/2008 9:30:41 AM Local time. +// Without RoundtripKind flag: 9/15/2008 9:30:41 AM Local time. +// 2008-09-15T09:30:41.7752486Z +// With RoundtripKind flag: 9/15/2008 9:30:41 AM Utc time. +// Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. +// 2008-09-15T09:30:41.7752486 +// With RoundtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. +// Without RoundtripKind flag: 9/15/2008 9:30:41 AM Unspecified time. +// 2008-09-15T09:30:41.7752486-04:00 +// With RoundtripKind flag: 9/15/2008 6:30:41 AM Local time. +// Without RoundtripKind flag: 9/15/2008 6:30:41 AM Local time. +// Mon, 15 Sep 2008 09:30:41 GMT +// With RoundtripKind flag: 9/15/2008 9:30:41 AM Utc time. +// Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse6.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse6.fs new file mode 100644 index 00000000000..9be9d6c76c6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse6.fs @@ -0,0 +1,35 @@ +module Parse6 + +open System + +let dateInfo = + [ "08/18/2018 07:22:16", "String with a date and time component" + "08/18/2018", "String with a date component only" + "8/2018", "String with a month and year component only" + "8/18", "String with a month and day component only" + "07:22:16", "String with a time component only" + "7 PM", "String with an hour and AM/PM designator only" + "2018-08-18T07:22:16.0000000Z", "UTC string that conforms to ISO 8601" + "2018-08-18T07:22:16.0000000-07:00", "Non-UTC string that conforms to ISO 8601" + "Sat, 18 Aug 2018 07:22:16 GMT", "String that conforms to RFC 1123" + "08/18/2018 07:22:16 -5:00", "String with date, time, and time zone information" ] + +printfn $"Today is {DateTime.Now:d}\n" + +for dateAsString, description in dateInfo do + printfn $"""{description + ":",-52} '{dateAsString}' --> {DateTime.Parse(dateAsString)}""" + + +// The example displays output like the following: +// Today is 2/22/2018 +// +// String with a date and time component: '08/18/2018 07:22:16' --> 8/18/2018 7:22:16 AM +// String with a date component only: '08/18/2018' --> 8/18/2018 12:00:00 AM +// String with a month and year component only: '8/2018' --> 8/1/2018 12:00:00 AM +// String with a month and day component only: '8/18' --> 8/18/2018 12:00:00 AM +// String with a time component only: '07:22:16' --> 2/22/2018 7:22:16 AM +// String with an hour and AM/PM designator only: '7 PM' --> 2/22/2018 7:00:00 PM +// UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000Z' --> 8/18/2018 12:22:16 AM +// Non-UTC string that conforms to ISO 8601: '2018-08-18T07:22:16.0000000-07:00' --> 8/18/2018 7:22:16 AM +// String that conforms to RFC 1123: 'Sat, 18 Aug 2018 07:22:16 GMT' --> 8/18/2018 12:22:16 AM +// String with date, time, and time zone information: '08/18/2018 07:22:16 -5:00' --> 8/18/2018 5:22:16 AM \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/fs.fsproj new file mode 100644 index 00000000000..e4819697d38 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net6.0 + + + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/ParseExact1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/ParseExact1.fs new file mode 100644 index 00000000000..8a74d73e398 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/ParseExact1.fs @@ -0,0 +1,77 @@ +module ParseExact1 + +// +open System +open System.Globalization + +[] +let main _ = + let provider = CultureInfo.InvariantCulture + + // Parse date-only value with invariant culture. + let dateString = "06/15/2008" + let format = "d" + try + let result = DateTime.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 = DateTime.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 = DateTime.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 but 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 = DateTime.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + let dateString = "15/06/2008 08:30" + let format = "g" + let provider = CultureInfo "fr-FR" + try + let result = DateTime.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + // Parse a date that includes seconds and milliseconds + // by using the French (France) and invariant cultures. + let dateString = "18/08/2015 06:30:15.006542" + let format = "dd/MM/yyyy HH:mm:ss.ffffff" + try + let result = DateTime.ParseExact(dateString, format, provider) + printfn $"{dateString} converts to {result}." + with :? FormatException -> + printfn $"{dateString} is not in the correct format." + + 0 + +// The example displays the following output: +// 06/15/2008 converts to 6/15/2008 12:00:00 AM. +// 6/15/2008 is not in the correct format. +// Sun 15 Jun 2008 8:30 AM -06:00 converts to 6/15/2008 7:30:00 AM. +// Sun 15 Jun 2008 8:30 AM -06 is not in the correct format. +// 15/06/2008 08:30 converts to 6/15/2008 8:30:00 AM. +// 18/08/2015 06:30:15.006542 converts to 8/18/2015 6:30:15 AM. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/fs.fsproj new file mode 100644 index 00000000000..ae3a72cb1aa --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2.fs new file mode 100644 index 00000000000..22377cc1227 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2.fs @@ -0,0 +1,78 @@ +// +open System +open System.Globalization + +[] +let main _ = + let enUS = CultureInfo "en-US" + + // Parse date with no style flags. + let dateString = " 5/01/2009 8:30 AM" + try + let dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + try + let dateValue = DateTime.ParseExact(dateString, "g", enUS, DateTimeStyles.AllowLeadingWhite) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Use custom formats with M and MM. + let dateString = "5/01/2009 09:00" + try + let dateValue = DateTime.ParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + try + let dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm", enUS, DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Parse a string with time zone information. + let dateString = "05/01/2009 01:30:42 PM -05:00" + try + let dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + try + let dateValue = DateTime.ParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.AdjustToUniversal) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + // Parse a string representing UTC. + let dateString = "2008-06-11T16:11:20.0904778Z" + try + let dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + try + let dateValue = DateTime.ParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind) + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + with :? FormatException -> + printfn $"'{dateString}' is not in an acceptable format." + + +// The example displays the following output: +// ' 5/01/2009 8:30 AM' is not in an acceptable format. +// Converted ' 5/01/2009 8:30 AM' to 5/1/2009 8:30:00 AM (Unspecified). +// Converted '5/01/2009 09:00' to 5/1/2009 9:00:00 AM (Unspecified). +// '5/01/2009 09:00' is not in an acceptable format. +// Converted '05/01/2009 01:30:42 PM -05:00' to 5/1/2009 11:30:42 AM (Local). +// Converted '05/01/2009 01:30:42 PM -05:00' to 5/1/2009 6:30:42 PM (Utc). +// Converted '2008-06-11T16:11:20.0904778Z' to 6/11/2008 9:11:20 AM (Local). +// Converted '2008-06-11T16:11:20.0904778Z' to 6/11/2008 4:11:20 PM (Utc). +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2/fs.fsproj new file mode 100644 index 00000000000..be188e41ff0 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2/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.DateTime.ParseExact/fs/parseexact3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact3.fs new file mode 100644 index 00000000000..567a036b4df --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact3.fs @@ -0,0 +1,37 @@ +module parseexact3 + +// +open System +open System.Globalization + +let formats = + [| "M/d/yyyy h:mm:ss tt"; "M/d/yyyy h:mm tt" + "MM/dd/yyyy hh:mm:ss"; "M/d/yyyy h:mm:ss" + "M/d/yyyy hh:mm tt"; "M/d/yyyy hh tt" + "M/d/yyyy h:mm"; "M/d/yyyy h:mm" + "MM/dd/yyyy hh:mm"; "M/dd/yyyy hh:mm" + "MM/d/yyyy HH:mm:ss.ffffff" |] + +let dateStrings = + [ "5/1/2009 6:32 PM"; "05/01/2009 6:32:05 PM" + "5/1/2009 6:32:00"; "05/01/2009 06:32" + "05/01/2009 06:32:00 PM"; "05/01/2009 06:32:00" + "08/28/2015 16:17:39.125"; "08/28/2015 16:17:39.125000" ] + +for dateString in dateStrings do + try + let dateValue = DateTime.ParseExact(dateString, formats, CultureInfo "en-US", DateTimeStyles.None) + printfn $"Converted '{dateString}' to {dateValue}." + with :? FormatException -> + printfn $"Unable to convert '{dateString}' to a date." + +// The example displays the following output: +// Converted '5/1/2009 6:32 PM' to 5/1/2009 6:32:00 PM. +// Converted '05/01/2009 6:32:05 PM' to 5/1/2009 6:32:05 PM. +// Converted '5/1/2009 6:32:00' to 5/1/2009 6:32:00 AM. +// Converted '05/01/2009 06:32' to 5/1/2009 6:32:00 AM. +// Converted '05/01/2009 06:32:00 PM' to 5/1/2009 6:32:00 PM. +// Converted '05/01/2009 06:32:00' to 5/1/2009 6:32:00 AM. +// Unable to convert '08/28/2015 16:17:39.125' to a date. +// Converted '08/28/2015 16:17:39.125000' to 8/28/2015 4:17:39 PM. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/Ticks.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/Ticks.fs new file mode 100644 index 00000000000..ada12d93ec5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/Ticks.fs @@ -0,0 +1,25 @@ +// +open System + +let centuryBegin = DateTime(2001, 1, 1) +let currentDate = DateTime.Now + +let elapsedTicks = currentDate.Ticks - centuryBegin.Ticks +let elapsedSpan = TimeSpan elapsedTicks + +printfn $"Elapsed from the beginning of the century to {currentDate:f}:" +printfn $" {elapsedTicks * 100L:N0} nanoseconds" +printfn $" {elapsedTicks:N0} ticks" +printfn $" {elapsedSpan.TotalSeconds:N2} seconds" +printfn $" {elapsedSpan.TotalMinutes:N2} minutes" +printfn $" {elapsedSpan.Days:N0} days, {elapsedSpan.Hours} hours, {elapsedSpan.Minutes} minutes, {elapsedSpan.Seconds} seconds" + +// This example displays an output similar to the following: +// +// Elapsed from the beginning of the century to Thursday, 14 November 2019 18:21: +// 595,448,498,171,000,000 nanoseconds +// 5,954,484,981,710,000 ticks +// 595,448,498.17 seconds +// 9,924,141.64 minutes +// 6,891 days, 18 hours, 21 minutes, 38 seconds +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/fs.fsproj new file mode 100644 index 00000000000..5a38c1bed9b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/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.DateTime.ToShortDateString/fs/ToShortDateString.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/ToShortDateString.fs new file mode 100644 index 00000000000..9780bb5e129 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/ToShortDateString.fs @@ -0,0 +1,41 @@ +// +open System +open System.Globalization +open System.Threading + +let dateToDisplay = DateTime(2009, 6, 1, 8, 42, 50) +let originalCulture = Thread.CurrentThread.CurrentCulture +// Change culture to en-US. +Thread.CurrentThread.CurrentCulture <- CultureInfo "en-US" +printfn "Displaying short date for {Thread.CurrentThread.CurrentCulture.Name} culture:" +printfn $" {dateToDisplay.ToShortDateString()} (Short Date String)" + +// Display using 'd' standard format specifier to illustrate it is +// identical to the string returned by ToShortDateString. +printfn $" {dateToDisplay:d} ('d' standard format specifier)\n" + +// Change culture to fr-FR. +Thread.CurrentThread.CurrentCulture <- CultureInfo "fr-FR" +printfn $"Displaying short date for {Thread.CurrentThread.CurrentCulture.Name} culture:" +printfn $" {dateToDisplay.ToShortDateString()}\n" + +// Change culture to nl-NL. +Thread.CurrentThread.CurrentCulture <- CultureInfo "nl-NL" +printfn $"Displaying short date for {Thread.CurrentThread.CurrentCulture.Name} culture:" +printfn $" {dateToDisplay.ToShortDateString()}" + +// Restore original culture. +Thread.CurrentThread.CurrentCulture <- originalCulture + + +// The example displays the following output: +// Displaying short date for en-US culture: +// 6/1/2009 (Short Date String) +// 6/1/2009 ('d' standard format specifier) +// +// Displaying short date for fr-FR culture: +// 01/06/2009 +// +// Displaying short date for nl-NL culture: +// 1-6-2009 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/fs.fsproj new file mode 100644 index 00000000000..d778f45d3da --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/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.DateTime.ToString/fs/ToString1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString1.fs new file mode 100644 index 00000000000..6d247ca84f6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString1.fs @@ -0,0 +1,29 @@ +module ToString1 + +// +open System +open System.Globalization + +let currentCulture = CultureInfo.CurrentCulture +let exampleDate = DateTime(2021, 5, 1, 18, 32, 6) + +// Change the current culture to en-US and display the date. +CultureInfo.CurrentCulture <- CultureInfo.GetCultureInfo "en-US" +printfn $"{exampleDate.ToString()}" + +// Change the current culture to fr-FR and display the date. +CultureInfo.CurrentCulture <- CultureInfo.GetCultureInfo "fr-FR" +printfn $"{exampleDate.ToString()}" + +// Change the current culture to ja-JP and display the date. +CultureInfo.CurrentCulture <- CultureInfo.GetCultureInfo "ja-JP" +printfn $"{exampleDate.ToString()}" + +// Restore the original culture +CultureInfo.CurrentCulture <- currentCulture + +// The example displays the following output to the console: +// 5/1/2021 6:32:06 PM +// 01/05/2021 18:32:06 +// 2021/05/01 18:32:06 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString2.fs new file mode 100644 index 00000000000..519dcbf6eb6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString2.fs @@ -0,0 +1,48 @@ +module ToString2 + +// +open System + +let dateValue = DateTime(2008, 6, 15, 21, 15, 07) +// Create a list of standard format strings. +let standardFmts = + [ "d"; "D"; "f"; "F"; "g"; "G"; "m"; "o" + "R"; "s"; "t"; "T"; "u"; "U"; "y" ] + +// Output date and time using each standard format string. +for standardFmt in standardFmts do + printfn $"{standardFmt}: {dateValue.ToString standardFmt}" +printfn "" + +// Create a list of some custom format strings. +let customFmts = + [ "h:mm:ss.ff t"; "d MMM yyyy"; "HH:mm:ss.f"; "dd MMM HH:mm:ss"; @"\Mon\t\h\: M"; "HH:mm:ss.ffffzzz" ] + +// Output date and time using each custom format string. +for customFmt in customFmts do + printfn $"'{customFmt}': {dateValue.ToString customFmt}" + +// This example displays the following output to the console: +// d: 6/15/2008 +// D: Sunday, June 15, 2008 +// f: Sunday, June 15, 2008 9:15 PM +// F: Sunday, June 15, 2008 9:15:07 PM +// g: 6/15/2008 9:15 PM +// G: 6/15/2008 9:15:07 PM +// m: June 15 +// o: 2008-06-15T21:15:07.0000000 +// R: Sun, 15 Jun 2008 21:15:07 GMT +// s: 2008-06-15T21:15:07 +// t: 9:15 PM +// T: 9:15:07 PM +// u: 2008-06-15 21:15:07Z +// U: Monday, June 16, 2008 4:15:07 AM +// y: June, 2008 +// +// 'h:mm:ss.ff t': 9:15:07.00 P +// 'd MMM yyyy': 15 Jun 2008 +// 'HH:mm:ss.f': 21:15:07.0 +// 'dd MMM HH:mm:ss': 15 Jun 21:15:07 +// '\Mon\t\h\: M': Month: 6 +// 'HH:mm:ss.ffffzzz': 21:15:07.0000-07:00 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString4.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString4.fs new file mode 100644 index 00000000000..485925a1a74 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString4.fs @@ -0,0 +1,34 @@ +module ToString4 + +// +open System +open System.Globalization + +let cultures = + [ CultureInfo.InvariantCulture + CultureInfo "en-us" + CultureInfo "fr-fr" + CultureInfo "de-DE" + CultureInfo "es-ES" + CultureInfo "ja-JP" ] + +let thisDate = DateTime(2009, 5, 1, 9, 0, 0) + +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/2009 09:00:00 +// In en-US, 5/1/2009 9:00:00 AM +// In fr-FR, 01/05/2009 09:00:00 +// In de-DE, 01.05.2009 09:00:00 +// In es-ES, 01/05/2009 9:00:00 +// In ja-JP, 2009/05/01 9:00:00 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/fs.fsproj new file mode 100644 index 00000000000..a5ac07e424d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net6.0 + + + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring3.fs new file mode 100644 index 00000000000..a45069461eb --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring3.fs @@ -0,0 +1,103 @@ +module tostring3 + +// +open System +open System.Globalization + +// Create a list of all supported standard date and time format specifiers. +let formats = + [ "d"; "D"; "f"; "F"; "g"; "G"; "m"; "o" + "r"; "s"; "t"; "T"; "u"; "U"; "Y" ] + +// Create a list of four cultures. +let cultures = + [ CultureInfo.GetCultureInfo "de-DE" + CultureInfo.GetCultureInfo "en-US" + CultureInfo.GetCultureInfo "es-ES" + CultureInfo.GetCultureInfo "fr-FR" ] + +// Define date to be displayed. +let dateToDisplay = DateTime(2008, 10, 31, 17, 4, 32) + +// Iterate each standard format specifier. +for formatSpecifier in formats do + for culture in cultures do + printfn $"{formatSpecifier} Format Specifier {culture.Name, 10} Culture {dateToDisplay.ToString(formatSpecifier, culture), 40}" + printfn "" + +// The example displays the following output: +// d Format Specifier de-DE Culture 31.10.2008 +// d Format Specifier en-US Culture 10/31/2008 +// d Format Specifier es-ES Culture 31/10/2008 +// d Format Specifier fr-FR Culture 31/10/2008 +// +// D Format Specifier de-DE Culture Freitag, 31. Oktober 2008 +// D Format Specifier en-US Culture Friday, October 31, 2008 +// D Format Specifier es-ES Culture viernes, 31 de octubre de 2008 +// D Format Specifier fr-FR Culture vendredi 31 octobre 2008 +// +// f Format Specifier de-DE Culture Freitag, 31. Oktober 2008 17:04 +// f Format Specifier en-US Culture Friday, October 31, 2008 5:04 PM +// f Format Specifier es-ES Culture viernes, 31 de octubre de 2008 17:04 +// f Format Specifier fr-FR Culture vendredi 31 octobre 2008 17:04 +// +// F Format Specifier de-DE Culture Freitag, 31. Oktober 2008 17:04:32 +// F Format Specifier en-US Culture Friday, October 31, 2008 5:04:32 PM +// F Format Specifier es-ES Culture viernes, 31 de octubre de 2008 17:04:32 +// F Format Specifier fr-FR Culture vendredi 31 octobre 2008 17:04:32 +// +// g Format Specifier de-DE Culture 31.10.2008 17:04 +// g Format Specifier en-US Culture 10/31/2008 5:04 PM +// g Format Specifier es-ES Culture 31/10/2008 17:04 +// g Format Specifier fr-FR Culture 31/10/2008 17:04 +// +// G Format Specifier de-DE Culture 31.10.2008 17:04:32 +// G Format Specifier en-US Culture 10/31/2008 5:04:32 PM +// G Format Specifier es-ES Culture 31/10/2008 17:04:32 +// G Format Specifier fr-FR Culture 31/10/2008 17:04:32 +// +// m Format Specifier de-DE Culture 31. Oktober +// m Format Specifier en-US Culture October 31 +// m Format Specifier es-ES Culture 31 de octubre +// m Format Specifier fr-FR Culture 31 octobre +// +// o Format Specifier de-DE Culture 2008-10-31T17:04:32.0000000 +// o Format Specifier en-US Culture 2008-10-31T17:04:32.0000000 +// o Format Specifier es-ES Culture 2008-10-31T17:04:32.0000000 +// o Format Specifier fr-FR Culture 2008-10-31T17:04:32.0000000 +// +// r Format Specifier de-DE Culture Fri, 31 Oct 2008 17:04:32 GMT +// r Format Specifier en-US Culture Fri, 31 Oct 2008 17:04:32 GMT +// r Format Specifier es-ES Culture Fri, 31 Oct 2008 17:04:32 GMT +// r Format Specifier fr-FR Culture Fri, 31 Oct 2008 17:04:32 GMT +// +// s Format Specifier de-DE Culture 2008-10-31T17:04:32 +// s Format Specifier en-US Culture 2008-10-31T17:04:32 +// s Format Specifier es-ES Culture 2008-10-31T17:04:32 +// s Format Specifier fr-FR Culture 2008-10-31T17:04:32 +// +// t Format Specifier de-DE Culture 17:04 +// t Format Specifier en-US Culture 5:04 PM +// t Format Specifier es-ES Culture 17:04 +// t Format Specifier fr-FR Culture 17:04 +// +// T Format Specifier de-DE Culture 17:04:32 +// T Format Specifier en-US Culture 5:04:32 PM +// T Format Specifier es-ES Culture 17:04:32 +// T Format Specifier fr-FR Culture 17:04:32 +// +// u Format Specifier de-DE Culture 2008-10-31 17:04:32Z +// u Format Specifier en-US Culture 2008-10-31 17:04:32Z +// u Format Specifier es-ES Culture 2008-10-31 17:04:32Z +// u Format Specifier fr-FR Culture 2008-10-31 17:04:32Z +// +// U Format Specifier de-DE Culture Freitag, 31. Oktober 2008 09:04:32 +// U Format Specifier en-US Culture Friday, October 31, 2008 9:04:32 AM +// U Format Specifier es-ES Culture viernes, 31 de octubre de 2008 9:04:32 +// U Format Specifier fr-FR Culture vendredi 31 octobre 2008 09:04:32 +// +// Y Format Specifier de-DE Culture Oktober 2008 +// Y Format Specifier en-US Culture October 2008 +// Y Format Specifier es-ES Culture octubre de 2008 +// Y Format Specifier fr-FR Culture octobre 2008 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring5.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring5.fs new file mode 100644 index 00000000000..e078f395b00 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/tostring5.fs @@ -0,0 +1,31 @@ +module tostring5 + +// +open System +open System.Globalization + +let formats = [ "G"; "MM/yyyy"; @"MM\/dd\/yyyy HH:mm"; "yyyyMMdd" ] +let cultureNames = [ "en-US"; "fr-FR" ] +let date = DateTime(2015, 8, 18, 13, 31, 17) +for cultureName in cultureNames do + let culture = CultureInfo cultureName + CultureInfo.CurrentCulture <- culture + + printfn $"{culture.NativeName}" + for format in formats do + printfn $" {format}: {date.ToString format}" + printfn "" + +// The example displays the following output: +// English (United States) +// G: 8/18/2015 1:31:17 PM +// MM/yyyy: 08/2015 +// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31 +// yyyyMMdd: 20150818 +// +// français (France) +// G: 18/08/2015 13:31:17 +// MM/yyyy: 08/2015 +// MM\/dd\/yyyy HH:mm: 08/18/2015 13:31 +// yyyyMMdd: 20150818 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/Today1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/Today1.fs new file mode 100644 index 00000000000..cfdf3136990 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/Today1.fs @@ -0,0 +1,19 @@ +// +open System + +// Get the current date. +let thisDay = DateTime.Today +// Display the date in the default (general) format. +printfn $"{thisDay}\n" +// Display the date in a variety of formats. +printfn $"{thisDay:d}" +printfn $"{thisDay:D}" +printfn $"{thisDay:g}" + +// The example displays output similar to the following: +// 5/3/2012 12:00:00 AM +// +// 5/3/2012 +// Thursday, May 03, 2012 +// 5/3/2012 12:00 AM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/fs.fsproj new file mode 100644 index 00000000000..60236be9fd9 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/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.DateTime.TryParse/fs/TryParse1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/TryParse1.fs new file mode 100644 index 00000000000..6bca5af2f88 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/TryParse1.fs @@ -0,0 +1,33 @@ +module TryParse1 + +// +open System +open System.Globalization + +let dateStrings = + [ "05/01/2009 14:57:32.8"; "2009-05-01 14:57:32.8" + "2009-05-01T14:57:32.8375298-04:00"; "5/01/2008" + "5/01/2008 14:57:32.80 -07:00" + "1 May 2008 2:57:32.8 PM"; "16-05-2009 1:00:32 PM" + "Fri, 15 May 2009 20:10:57 GMT" ] + +printfn $"Attempting to parse strings using {CultureInfo.CurrentCulture.Name} culture." +for dateString in dateStrings do + match DateTime.TryParse dateString with + | true, dateValue -> + printfn $" Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $" Unable to parse '{dateString}'." + + +// The example displays output like the following: +// Attempting to parse strings using en-US culture. +// Converted '05/01/2009 14:57:32.8' to 5/1/2009 2:57:32 PM (Unspecified). +// Converted '2009-05-01 14:57:32.8' to 5/1/2009 2:57:32 PM (Unspecified). +// Converted '2009-05-01T14:57:32.8375298-04:00' to 5/1/2009 11:57:32 AM (Local). +// Converted '5/01/2008' to 5/1/2008 12:00:00 AM (Unspecified). +// Converted '5/01/2008 14:57:32.80 -07:00' to 5/1/2008 2:57:32 PM (Local). +// Converted '1 May 2008 2:57:32.8 PM' to 5/1/2008 2:57:32 PM (Unspecified). +// Unable to parse '16-05-2009 1:00:32 PM'. +// Converted 'Fri, 15 May 2009 20:10:57 GMT' to 5/15/2009 1:10:57 PM (Local). +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/fs.fsproj new file mode 100644 index 00000000000..a50586fa037 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/tryparse2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/tryparse2.fs new file mode 100644 index 00000000000..9956da3c10d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/tryparse2.fs @@ -0,0 +1,65 @@ +module tryparse2 + +// +open System +open System.Globalization + +[] +let main _ = + // Parse a date and time with no styles. + let dateString = "03/01/2009 10:00 AM" + let culture = CultureInfo.CreateSpecificCulture "en-US" + let styles = DateTimeStyles.None + match DateTime.TryParse(dateString, culture, styles) with + | true, dateResult -> + printfn $"{dateString} converted to {dateResult} {dateResult.Kind}." + | _ -> + printfn $"Unable to convert {dateString} to a date and time." + + // Parse the same date and time with the AssumeLocal style. + let styles = DateTimeStyles.AssumeLocal + match DateTime.TryParse(dateString, culture, styles) with + | true, dateResult -> + printfn $"{dateString} converted to {dateResult} {dateResult.Kind}." + | _ -> + printfn $"Unable to convert {dateString} to a date and time." + + // Parse a date and time that is assumed to be local. + // This time is five hours behind UTC. The local system's time zone is + // eight hours behind UTC. + let dateString = "2009/03/01T10:00:00-5:00" + let styles = DateTimeStyles.AssumeLocal + match DateTime.TryParse(dateString, culture, styles) with + | true, dateResult -> + printfn $"{dateString} converted to {dateResult} {dateResult.Kind}." + | _ -> + printfn $"Unable to convert {dateString} to a date and time." + + // Attempt to convert a string in improper ISO 8601 format. + let dateString = "03/01/2009T10:00:00-5:00" + match DateTime.TryParse(dateString, culture, styles) with + | true, dateResult -> + printfn $"{dateString} converted to {dateResult} {dateResult.Kind}." + | _ -> + printfn $"Unable to convert {dateString} to a date and time." + + // Assume a date and time string formatted for the fr-FR culture is the local + // time and convert it to UTC. + let dateString = "2008-03-01 10:00" + let culture = CultureInfo.CreateSpecificCulture "fr-FR" + let styles = DateTimeStyles.AdjustToUniversal ||| DateTimeStyles.AssumeLocal + match DateTime.TryParse(dateString, culture, styles) with + | true, dateResult -> + printfn $"{dateString} converted to {dateResult} {dateResult.Kind}." + | _ -> + printfn $"Unable to convert {dateString} to a date and time." + + 0 + +// The example displays the following output to the console: +// 03/01/2009 10:00 AM converted to 3/1/2009 10:00:00 AM Unspecified. +// 03/01/2009 10:00 AM converted to 3/1/2009 10:00:00 AM Local. +// 2009/03/01T10:00:00-5:00 converted to 3/1/2009 7:00:00 AM Local. +// Unable to convert 03/01/2009T10:00:00-5:00 to a date and time. +// 2008-03-01 10:00 converted to 3/1/2008 6:00:00 PM Utc. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact1.fs new file mode 100644 index 00000000000..0d4ff701519 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact1.fs @@ -0,0 +1,79 @@ +// +open System +open System.Globalization + +[] +let main _ = + let enUS = CultureInfo "en-US" + + // Parse date with no style flags. + let dateString = " 5/01/2009 8:30 AM" + match DateTime.TryParseExact(dateString, "g", enUS, DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + match DateTime.TryParseExact(dateString, "g", enUS, DateTimeStyles.AllowLeadingWhite) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Use custom formats with M and MM. + let dateString = "5/01/2009 09:00" + match DateTime.TryParseExact(dateString, "M/dd/yyyy hh:mm", enUS, DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + match DateTime.TryParseExact(dateString, "MM/dd/yyyy hh:mm", enUS, DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Parse a string with time zone information. + let dateString = "05/01/2009 01:30:42 PM -05:00" + match DateTime.TryParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Allow a leading space in the date string. + match DateTime.TryParseExact(dateString, "MM/dd/yyyy hh:mm:ss tt zzz", enUS, DateTimeStyles.AdjustToUniversal) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + // Parse a string representing UTC. + let dateString = "2008-06-11T16:11:20.0904778Z" + match DateTime.TryParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + match DateTime.TryParseExact(dateString, "o", CultureInfo.InvariantCulture, DateTimeStyles.RoundtripKind) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue} ({dateValue.Kind})." + | _ -> + printfn $"'{dateString}' is not in an acceptable format." + + 0 + + // The example displays the following output: + // ' 5/01/2009 8:30 AM' is not in an acceptable format. + // Converted ' 5/01/2009 8:30 AM' to 5/1/2009 8:30:00 AM (Unspecified). + // Converted '5/01/2009 09:00' to 5/1/2009 9:00:00 AM (Unspecified). + // '5/01/2009 09:00' is not in an acceptable format. + // Converted '05/01/2009 01:30:42 PM -05:00' to 5/1/2009 11:30:42 AM (Local). + // Converted '05/01/2009 01:30:42 PM -05:00' to 5/1/2009 6:30:42 PM (Utc). + // Converted '2008-06-11T16:11:20.0904778Z' to 6/11/2008 9:11:20 AM (Local). + // Converted '2008-06-11T16:11:20.0904778Z' to 6/11/2008 4:11:20 PM (Utc). + // \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs new file mode 100644 index 00000000000..d3f0e0e03a8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs @@ -0,0 +1,32 @@ +// +open System +open System.Globalization + +let formats= + [| "M/d/yyyy h:mm:ss tt"; "M/d/yyyy h:mm tt" + "MM/dd/yyyy hh:mm:ss"; "M/d/yyyy h:mm:ss" + "M/d/yyyy hh:mm tt"; "M/d/yyyy hh tt" + "M/d/yyyy h:mm"; "M/d/yyyy h:mm" + "MM/dd/yyyy hh:mm"; "M/dd/yyyy hh:mm" |] + +let dateStrings = + [ "5/1/2009 6:32 PM"; "05/01/2009 6:32:05 PM" + "5/1/2009 6:32:00"; "05/01/2009 06:32" + "05/01/2009 06:32:00 PM"; "05/01/2009 06:32:00" ] + +for dateString in dateStrings do + match DateTime.TryParseExact(dateString, formats, CultureInfo "en-US", DateTimeStyles.None) with + | true, dateValue -> + printfn $"Converted '{dateString}' to {dateValue}." + | _ -> + printfn $"Unable to convert '{dateString}' to a date." + + +// The example displays the following output: +// Converted '5/1/2009 6:32 PM' to 5/1/2009 6:32:00 PM. +// Converted '05/01/2009 6:32:05 PM' to 5/1/2009 6:32:05 PM. +// Converted '5/1/2009 6:32:00' to 5/1/2009 6:32:00 AM. +// Converted '05/01/2009 06:32' to 5/1/2009 6:32:00 AM. +// Converted '05/01/2009 06:32:00 PM' to 5/1/2009 6:32:00 PM. +// Converted '05/01/2009 06:32:00' to 5/1/2009 6:32:00 AM. +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/fs.fsproj new file mode 100644 index 00000000000..3bcf1e70fb5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/Year.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/Year.fs new file mode 100644 index 00000000000..bda734f84dc --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/Year.fs @@ -0,0 +1,21 @@ +// +open System +open System.Globalization +open System.Threading + +// Initialize date variable and display year +let date1 = DateTime(2008, 1, 1, 6, 32, 0) +printfn $"{date1.Year}" // Displays 2008 + +// Set culture to th-TH +Thread.CurrentThread.CurrentCulture <- CultureInfo "th-TH" +printfn $"{date1.Year}" // Displays 2008 + +// display year using current culture's calendar +let thaiCalendar = CultureInfo.CurrentCulture.Calendar +printfn $"{thaiCalendar.GetYear date1}" // Displays 2551 + +// display year using Persian calendar +let persianCalendar = PersianCalendar() +printfn $"{persianCalendar.GetYear date1}" // Displays 1386 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/fs.fsproj new file mode 100644 index 00000000000..9fb25865085 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/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.datetime.addmilliseconds/fs/addmilliseconds2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/addmilliseconds2.fs new file mode 100644 index 00000000000..8e1949a3cfe --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/addmilliseconds2.fs @@ -0,0 +1,24 @@ +open System + +// +let dateFormat = "MM/dd/yyyy hh:mm:ss.fffffff" +let date1 = DateTime(2010, 9, 8, 16, 0, 0) +printfn $"Original date: {date1.ToString dateFormat} ({date1.Ticks:N0} ticks)\n" + +let date2 = date1.AddMilliseconds 1 +printfn $"Second date: {date2.ToString dateFormat} ({date2.Ticks:N0} ticks)" +printfn $"Difference between dates: {date2 - date1} ({date2.Ticks - date1.Ticks:N0} ticks)\n" + +let date3 = date1.AddMilliseconds 1.5 +printfn $"Third date: {date3.ToString dateFormat} ({date3.Ticks:N0} ticks)" +printfn $"Difference between dates: {date3 - date1} ({date3.Ticks - date1.Ticks:N0} ticks)" + +// The example displays the following output: +// Original date: 09/08/2010 04:00:00.0000000 (634,195,584,000,000,000 ticks) +// +// Second date: 09/08/2010 04:00:00.0010000 (634,195,584,000,010,000 ticks) +// Difference between dates: 00:00:00.0010000 (10,000 ticks) +// +// Third date: 09/08/2010 04:00:00.0020000 (634,195,584,000,020,000 ticks) +// Difference between dates: 00:00:00.0020000 (20,000 ticks) +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/fs.fsproj new file mode 100644 index 00000000000..6a26342c861 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/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.datetime.addminutes/fs/addminutes1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/addminutes1.fs new file mode 100644 index 00000000000..bc1ff760213 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/addminutes1.fs @@ -0,0 +1,32 @@ +// +open System + +let dateValue = DateTime(2013, 9, 15, 12, 0, 0) + +let minutes = + [ 0.01667; 0.08333; 0.16667; 0.25; 0.33333 + 0.5; 0.66667; 1; 2; 15; 30; 17; 45 + 60; 180; 60. * 24. ] + +for minute in minutes do + printfn $"{dateValue} + {minute} minute(s) = {dateValue.AddMinutes minute}" + + +// The example displays the following output on a system whose current culture is en-US: +// 9/15/2013 12:00:00 PM + 0.01667 minute(s) = 9/15/2013 12:00:01 PM +// 9/15/2013 12:00:00 PM + 0.08333 minute(s) = 9/15/2013 12:00:05 PM +// 9/15/2013 12:00:00 PM + 0.16667 minute(s) = 9/15/2013 12:00:10 PM +// 9/15/2013 12:00:00 PM + 0.25 minute(s) = 9/15/2013 12:00:15 PM +// 9/15/2013 12:00:00 PM + 0.33333 minute(s) = 9/15/2013 12:00:20 PM +// 9/15/2013 12:00:00 PM + 0.5 minute(s) = 9/15/2013 12:00:30 PM +// 9/15/2013 12:00:00 PM + 0.66667 minute(s) = 9/15/2013 12:00:40 PM +// 9/15/2013 12:00:00 PM + 1 minute(s) = 9/15/2013 12:01:00 PM +// 9/15/2013 12:00:00 PM + 2 minute(s) = 9/15/2013 12:02:00 PM +// 9/15/2013 12:00:00 PM + 15 minute(s) = 9/15/2013 12:15:00 PM +// 9/15/2013 12:00:00 PM + 30 minute(s) = 9/15/2013 12:30:00 PM +// 9/15/2013 12:00:00 PM + 17 minute(s) = 9/15/2013 12:17:00 PM +// 9/15/2013 12:00:00 PM + 45 minute(s) = 9/15/2013 12:45:00 PM +// 9/15/2013 12:00:00 PM + 60 minute(s) = 9/15/2013 1:00:00 PM +// 9/15/2013 12:00:00 PM + 180 minute(s) = 9/15/2013 3:00:00 PM +// 9/15/2013 12:00:00 PM + 1440 minute(s) = 9/16/2013 12:00:00 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/fs.fsproj new file mode 100644 index 00000000000..7089bcad523 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/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.datetime.addmonths/fs/addmonths1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/addmonths1.fs new file mode 100644 index 00000000000..78c76d6b88d --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/addmonths1.fs @@ -0,0 +1,25 @@ +// +open System + +let dat = DateTime(2015, 12, 31) +for i = 0 to 15 do + printfn $"{dat.AddMonths i:d}" + +// The example displays the following output: +// 12/31/2015 +// 1/31/2016 +// 2/29/2016 +// 3/31/2016 +// 4/30/2016 +// 5/31/2016 +// 6/30/2016 +// 7/31/2016 +// 8/31/2016 +// 9/30/2016 +// 10/31/2016 +// 11/30/2016 +// 12/31/2016 +// 1/31/2017 +// 2/28/2017 +// 3/31/2017 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/fs.fsproj new file mode 100644 index 00000000000..397a559baf7 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/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.datetime.addseconds/fs/addseconds1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/addseconds1.fs new file mode 100644 index 00000000000..cd933e50bf6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/addseconds1.fs @@ -0,0 +1,25 @@ +// +open System + +let dateFormat = "MM/dd/yyyy hh:mm:ss" +let date1 = DateTime(2014, 9, 8, 16, 0, 0) +printfn $"Original date: {date1.ToString dateFormat} ({date1.Ticks:N0} ticks)\n" + +let date2 = date1.AddSeconds 30 +printfn $"Second date: {date2.ToString dateFormat} ({date2.Ticks:N0} ticks)" +printfn $"Difference between dates: {date2 - date1} ({date2.Ticks - date1.Ticks:N0} ticks)\n" + +// Add 1 day's worth of seconds (60 secs. * 60 mins * 24 hrs. +let date3 = date1.AddSeconds(60. * 60. * 24.) +printfn $"Third date: {date3.ToString dateFormat} ({date3.Ticks:N0} ticks)" +printfn $"Difference between dates: {date3 - date1} ({date3.Ticks - date1.Ticks:N0} ticks)" + +// The example displays the following output: +// Original date: 09/08/2014 04:00:00 (635,457,888,000,000,000 ticks) +// +// Second date: 09/08/2014 04:00:30 (635,457,888,300,000,000 ticks) +// Difference between dates: 00:00:30 (300,000,000 ticks) +// +// Third date: 09/09/2014 04:00:00 (635,458,752,000,000,000 ticks) +// Difference between dates: 1.00:00:00 (864,000,000,000 ticks) +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/fs.fsproj new file mode 100644 index 00000000000..536b39c249b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/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.datetime.addyears/fs/addyears1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/addyears1.fs new file mode 100644 index 00000000000..42963239ab5 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/addyears1.fs @@ -0,0 +1,51 @@ +// +open System + +let baseDate = DateTime(2000, 2, 29) +printfn $" Base Date: {baseDate:d}\n" + +// Show dates of previous fifteen years. +for i = -1 downto -15 do + printfn $"{-i,2} year(s) ago: {baseDate.AddYears i:d}" +printfn "" + +// Show dates of next fifteen years. +for i = 1 to 15 do + printfn $"{i,2} year(s) from now: {baseDate.AddYears i:d}" + + +// The example displays the following output: +// Base Date: 2/29/2000 +// +// 1 year(s) ago: 2/28/1999 +// 2 year(s) ago: 2/28/1998 +// 3 year(s) ago: 2/28/1997 +// 4 year(s) ago: 2/29/1996 +// 5 year(s) ago: 2/28/1995 +// 6 year(s) ago: 2/28/1994 +// 7 year(s) ago: 2/28/1993 +// 8 year(s) ago: 2/29/1992 +// 9 year(s) ago: 2/28/1991 +// 10 year(s) ago: 2/28/1990 +// 11 year(s) ago: 2/28/1989 +// 12 year(s) ago: 2/29/1988 +// 13 year(s) ago: 2/28/1987 +// 14 year(s) ago: 2/28/1986 +// 15 year(s) ago: 2/28/1985 +// +// 1 year(s) from now: 2/28/2001 +// 2 year(s) from now: 2/28/2002 +// 3 year(s) from now: 2/28/2003 +// 4 year(s) from now: 2/29/2004 +// 5 year(s) from now: 2/28/2005 +// 6 year(s) from now: 2/28/2006 +// 7 year(s) from now: 2/28/2007 +// 8 year(s) from now: 2/29/2008 +// 9 year(s) from now: 2/28/2009 +// 10 year(s) from now: 2/28/2010 +// 11 year(s) from now: 2/28/2011 +// 12 year(s) from now: 2/29/2012 +// 13 year(s) from now: 2/28/2013 +// 14 year(s) from now: 2/28/2014 +// 15 year(s) from now: 2/28/2015 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/fs.fsproj new file mode 100644 index 00000000000..42f16724ef3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/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.datetime.compare/fs/compare1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/compare1.fs new file mode 100644 index 00000000000..fd1916391d4 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/compare1.fs @@ -0,0 +1,20 @@ +open System + +// +let date1 = DateTime(2009, 8, 1, 0, 0, 0) +let date2 = DateTime(2009, 8, 1, 12, 0, 0) +let result = DateTime.Compare(date1, date2) + +let relationship = + if result < 0 then + "is earlier than" + elif result = 0 then + "is the same time as" + else + "is later than" + +printfn $"{date1} {relationship} {date2}" + +// The example displays the following output for en-us culture: +// 8/1/2009 12:00:00 AM is earlier than 8/1/2009 12:00:00 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/fs.fsproj new file mode 100644 index 00000000000..95c2b51f958 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/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.datetime.constructor/fs/ctorexample1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs new file mode 100644 index 00000000000..56ea4fc5734 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs @@ -0,0 +1,60 @@ +module ctorexample1 + +open System + +let showYMD () = + // + let date1 = DateTime(2010, 8, 18) + printfn $"{date1}" + + // The example displays the following output: + // 8/18/2010 12:00:00 AM + // + +let showYMDHMS () = + // + let date1 = DateTime(2010, 8, 18, 16, 32, 0) + printfn $"{date1}" + + // The example displays the following output, in this case for en-us culture: + // 8/18/2010 4:32:00 PM + // + +let showYMDHMSMs () = + // + let date1 = DateTime(2010, 8, 18, 16, 32, 18, 500) + + date1.ToString "M/dd/yyyy h:mm:ss.fff tt" + |> printfn "%s" + + // The example displays the following output, in this case for en-us culture: + // 8/18/2010 4:32:18.500 PM + // + +let showYMDHMSKind () = + // + let date1 = DateTime(2010, 8, 18, 16, 32, 0, DateTimeKind.Local) + printfn $"{date1} {date1.Kind}" + + // The example displays the following output, in this case for en-us culture: + // 8/18/2010 4:32:00 PM Local + // + +let showYMDHMSMsKind () = + // + let date1 = DateTime(2010, 8, 18, 16, 32, 18, 500, DateTimeKind.Local) + printfn $"""{date1.ToString "M/dd/yyyy h:mm:ss.fff tt"} {date1.Kind}""" + + // The example displays the following output, in this case for en-us culture: + // 8/18/2010 4:32:18.500 PM Local + // + +showYMD () +printfn "-----" +showYMDHMS () +printfn "-----" +showYMDHMSMs () +printfn "-----" +showYMDHMSKind () +printfn "-----" +showYMDHMSMsKind () \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample2.fs new file mode 100644 index 00000000000..bfcd667c9b2 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample2.fs @@ -0,0 +1,51 @@ +module ctorexample2 + +// +open System +open System.Globalization +open System.Text.RegularExpressions +open System.Threading + +let getCalendarName (cal: Calendar) = + Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value + +printfn "Using the Persian Calendar:" +let persian = PersianCalendar() +let date1 = DateTime(1389, 5, 27, persian) +printfn $"{date1}" +printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1}\n" + +printfn "Using the Hijri Calendar:" +// Get current culture so it can later be restored. +let dftCulture = Thread.CurrentThread.CurrentCulture + +// Define Hijri calendar. +let hijri = HijriCalendar() +// Make ar-SY the current culture and Hijri the current calendar. +Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY" +let current = CultureInfo.CurrentCulture +current.DateTimeFormat.Calendar <- hijri + +let dFormat = + let dFormat = current.DateTimeFormat.ShortDatePattern + // Ensure year is displayed as four digits. + Regex.Replace(dFormat, "/yy$", "/yyyy") + +current.DateTimeFormat.ShortDatePattern <- dFormat +let date2 = DateTime(1431, 9, 9, hijri) +printfn $"{current} culture using the {getCalendarName hijri} calendar: {date2:d}" + +// Restore previous culture. +Thread.CurrentThread.CurrentCulture <- dftCulture +printfn $"{CultureInfo.CurrentCulture} culture using the {getCalendarName CultureInfo.CurrentCulture.Calendar} calendar: {date2:d}" + + +// The example displays the following output: +// Using the Persian Calendar: +// 8/18/2010 12:00:00 AM +// 5/27/1389 +// +// Using the Hijri Calendar: +// ar-SY culture using the Hijri calendar: 09/09/1431 +// en-US culture using the Gregorian calendar: 8/18/2010 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample4.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample4.fs new file mode 100644 index 00000000000..d300af9001a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample4.fs @@ -0,0 +1,53 @@ +module ctorexample4 + +// +open System +open System.Globalization +open System.Text.RegularExpressions +open System.Threading + +let getCalendarName (cal: Calendar) = + Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value + +printfn "Using the Persian Calendar:" +let persian = PersianCalendar() +let date1 = DateTime(1389, 5, 27, 16, 32, 0, persian) +printfn $"{date1}" +let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator +printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}%02i{persian.GetMinute date1}{sep}%02i{persian.GetSecond date1}\n" + +printfn "Using the Hijri Calendar:" + +// Get current culture so it can later be restored. +let dftCulture = Thread.CurrentThread.CurrentCulture + +// Define Hijri calendar. +let hijri = HijriCalendar() + +// Make ar-SY the current culture and Hijri the current calendar. +Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY" +let current = CultureInfo.CurrentCulture +current.DateTimeFormat.Calendar <- hijri +let dFormat = + let dFormat = current.DateTimeFormat.ShortDatePattern + // Ensure year is displayed as four digits. + Regex.Replace(dFormat, "/yy$", "/yyyy") + +current.DateTimeFormat.ShortDatePattern <- dFormat +let date2 = DateTime(1431, 9, 9, 16, 32, 18, hijri) +printfn $"{current} culture using the {getCalendarName hijri} calendar: {date2:g}" + +// Restore previous culture. +Thread.CurrentThread.CurrentCulture <- dftCulture +printfn $"{CultureInfo.CurrentCulture} culture using the {getCalendarName CultureInfo.CurrentCulture.Calendar} calendar: {date2:g}" + + +// The example displays the following output: +// Using the Persian Calendar: +// 8/18/2010 4:32:00 PM +// 5/27/1389 16:32:00 +// +// Using the Hijri Calendar: +// ar-SY culture using the Hijri calendar: 09/09/1431 04:32 م +// en-US culture using the Gregorian calendar: 8/18/2010 4:32 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample6.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample6.fs new file mode 100644 index 00000000000..3157586c5b8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample6.fs @@ -0,0 +1,53 @@ +module ctorexample6 + +// +open System +open System.Globalization +open System.Text.RegularExpressions +open System.Threading + +let getCalendarName (cal: Calendar) = + Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value + +printfn "Using the Persian Calendar:" +let persian = PersianCalendar() +let date1 = DateTime(1389, 5, 27, 16, 32, 18, 500, persian) +printfn $"""{date1.ToString("M/dd/yyyy h:mm:ss.fff tt")}""" +let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator +printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}%02i{persian.GetMinute date1}{sep}%02i{persian.GetSecond date1}.%.3f{persian.GetMilliseconds date1}\n" + +printfn "Using the Hijri Calendar:" +// Get current culture so it can later be restored. +let dftCulture = Thread.CurrentThread.CurrentCulture + +// Define Hijri calendar. +let hijri = HijriCalendar() +// Make ar-SY the current culture and Hijri the current calendar. +Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY" +let current = CultureInfo.CurrentCulture +current.DateTimeFormat.Calendar <- hijri + +let dFormat = + let dFormat = current.DateTimeFormat.ShortDatePattern + // Ensure year is displayed as four digits. + Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff" + +let fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "}" +let date2 = DateTime(1431, 9, 9, 16, 32, 18, 500, hijri) +Console.WriteLine(fmtString, current, getCalendarName hijri, date2) + +// Restore previous culture. +Thread.CurrentThread.CurrentCulture <- dftCulture +let dFormat2 = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " H:mm:ss.fff" +let fmtString2 = "{0} culture using the {1} calendar: {2:" + dFormat + "}" +Console.WriteLine(fmtString2, CultureInfo.CurrentCulture, getCalendarName CultureInfo.CurrentCulture.Calendar, date2) + + +// The example displays the following output: +// 8/18/2010 4:32:18.500 PM +// 5/27/1389 16:32:18.500 +// +// Using the Hijri Calendar: +// ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500 +// en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample9.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample9.fs new file mode 100644 index 00000000000..ea604193ea8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample9.fs @@ -0,0 +1,54 @@ +module ctorexample9 + +// +open System +open System.Globalization +open System.Text.RegularExpressions +open System.Threading + +let getCalendarName (cal: Calendar) = + Regex.Match(string cal, "\\.(\\w+)Calendar").Groups[1].Value + +printfn "Using the Persian Calendar:" +let persian = PersianCalendar() +let date1 = DateTime(1389, 5, 27, 16, 32, 18, 500, persian, DateTimeKind.Local) +printfn $"""{date1.ToString "M/dd/yyyy h:mm:ss.fff tt"} {date1.Kind}""" +let sep = DateTimeFormatInfo.CurrentInfo.TimeSeparator +printfn $"{persian.GetMonth date1}/{persian.GetDayOfMonth date1}/{persian.GetYear date1} {persian.GetHour date1}{sep}{persian.GetMinute date1:D2}{sep}{persian.GetSecond date1:D2}.{persian.GetMilliseconds date1:G3} {date1.Kind}\n" + +printfn "Using the Hijri Calendar:" +// Get current culture so it can later be restored. +let dftCulture = Thread.CurrentThread.CurrentCulture + +// Define Hijri calendar. +let hijri = HijriCalendar() +// Make ar-SY the current culture and Hijri the current calendar. +Thread.CurrentThread.CurrentCulture <- CultureInfo "ar-SY" +let current = CultureInfo.CurrentCulture +current.DateTimeFormat.Calendar <- hijri + +let dFormat = + let dFormat = current.DateTimeFormat.ShortDatePattern + // Ensure year is displayed as four digits. + Regex.Replace(dFormat, "/yy$", "/yyyy") + " H:mm:ss.fff" + +let fmtString = "{0} culture using the {1} calendar: {2:" + dFormat + "} {3}" +let date2 = DateTime(1431, 9, 9, 16, 32, 18, 500, hijri, DateTimeKind.Local) +Console.WriteLine(fmtString, current, getCalendarName hijri, date2, date2.Kind) + +// Restore previous culture. +Thread.CurrentThread.CurrentCulture <- dftCulture +let dFormat2 = DateTimeFormatInfo.CurrentInfo.ShortDatePattern + " H:mm:ss.fff" +let fmtString2 = "{0} culture using the {1} calendar: {2:" + dFormat2 + "} {3}" +Console.WriteLine(fmtString2, CultureInfo.CurrentCulture, getCalendarName CultureInfo.CurrentCulture.Calendar, date2, date2.Kind) + + +// The example displays the following output: +// Using the Persian Calendar: +// 8/18/2010 4:32:18.500 PM Local +// 5/27/1389 16:32:18.500 Local +// +// Using the Hijri Calendar: +// ar-SY culture using the Hijri calendar: 09/09/1431 16:32:18.500 Local +// en-US culture using the Gregorian calendar: 8/18/2010 16:32:18.500 Local +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/fs.fsproj new file mode 100644 index 00000000000..4ab5c1885fa --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/fs.fsproj @@ -0,0 +1,13 @@ + + + Exe + net6.0 + + + + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/dayofyear2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/dayofyear2.fs new file mode 100644 index 00000000000..4d68b119975 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/dayofyear2.fs @@ -0,0 +1,22 @@ +// +open System + +let dec31 = DateTime(2010, 12, 31) +for i = 0 to 10 do + let dateToDisplay = dec31.AddYears i + let leap = if DateTime.IsLeapYear dateToDisplay.Year then "(Leap Year)" else "" + printfn $"{dateToDisplay:d}: day {dateToDisplay.DayOfYear} of {dateToDisplay.Year} {leap}" + +// The example displays the following output: +// 12/31/2010: day 365 of 2010 +// 12/31/2011: day 365 of 2011 +// 12/31/2012: day 366 of 2012 (Leap Year) +// 12/31/2013: day 365 of 2013 +// 12/31/2014: day 365 of 2014 +// 12/31/2015: day 365 of 2015 +// 12/31/2016: day 366 of 2016 (Leap Year) +// 12/31/2017: day 365 of 2017 +// 12/31/2018: day 365 of 2018 +// 12/31/2019: day 365 of 2019 +// 12/31/2020: day 366 of 2020 (Leap Year) +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/fs.fsproj new file mode 100644 index 00000000000..6684b9aa46b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/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.datetime.daysinmonth/fs/daysinmonth3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/daysinmonth3.fs new file mode 100644 index 00000000000..ad1b11f2cd3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/daysinmonth3.fs @@ -0,0 +1,46 @@ +// +open System +open System.Globalization + +let years = [| 2012; 2014 |] +let dtfi = DateTimeFormatInfo.CurrentInfo +printfn $"""Days in the Month for the {CultureInfo.CurrentCulture.Name} culture using the {dtfi.Calendar.GetType().Name.Replace("Calendar", "")} calendar\n""" +printfn $"""{"Year",-10}{"Month",-15}{"Days",4}\n""" + +for year in years do + for i = 0 to dtfi.MonthNames.Length - 1 do + if not (String.IsNullOrEmpty dtfi.MonthNames[i]) then + printfn $"{year,-10}{dtfi.MonthNames[i],-15}{DateTime.DaysInMonth(year, i + 1),4}" + printfn "" + +// The example displays the following output: +// Days in the Month for the en-US culture using the Gregorian calendar +// +// Year Month Days +// +// 2012 January 31 +// 2012 February 29 +// 2012 March 31 +// 2012 April 30 +// 2012 May 31 +// 2012 June 30 +// 2012 July 31 +// 2012 August 31 +// 2012 September 30 +// 2012 October 31 +// 2012 November 30 +// 2012 December 31 +// +// 2014 January 31 +// 2014 February 28 +// 2014 March 31 +// 2014 April 30 +// 2014 May 31 +// 2014 June 30 +// 2014 July 31 +// 2014 August 31 +// 2014 September 30 +// 2014 October 31 +// 2014 November 30 +// 2014 December 31 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/fs.fsproj new file mode 100644 index 00000000000..0ff36c0c601 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/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.datetime.frombinary/fs/frombinary1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/frombinary1.fs new file mode 100644 index 00000000000..2a6c752eda8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/frombinary1.fs @@ -0,0 +1,15 @@ +// +open System + +let localDate = DateTime(2010, 3, 14, 2, 30, 0, DateTimeKind.Local) +let binLocal = localDate.ToBinary() +if TimeZoneInfo.Local.IsInvalidTime localDate then + printfn $"{localDate} is an invalid time in the {TimeZoneInfo.Local.StandardName} zone." + +let localDate2 = DateTime.FromBinary binLocal +printfn $"{localDate} = {localDate2}: {localDate.Equals localDate2}" + +// The example displays the following output: +// 3/14/2010 2:30:00 AM is an invalid time in the Pacific Standard Time zone. +// 3/14/2010 2:30:00 AM = 3/14/2010 3:30:00 AM: False +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/fs.fsproj new file mode 100644 index 00000000000..8e502ff94d8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/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.datetime.fromfiletime/fs/fromfiletime1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs new file mode 100644 index 00000000000..e8433385c74 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs @@ -0,0 +1,14 @@ +// +open System + +let date1 = DateTime(2010, 3, 14, 2, 30, 00) +printfn $"Invalid Time: {TimeZoneInfo.Local.IsInvalidTime date1}" + +let ft = date1.ToFileTime() +let date2 = DateTime.FromFileTime ft +printfn $"{date1} -> {date2}" + +// The example displays the following output: +// Invalid Time: True +// 3/14/2010 2:30:00 AM -> 3/14/2010 3:30:00 AM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fs.fsproj new file mode 100644 index 00000000000..242b045f4cd --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.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.datetime.now/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/fs.fsproj new file mode 100644 index 00000000000..7c8505492f8 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/fs.fsproj @@ -0,0 +1,10 @@ + + + Exe + net6.0 + + + + + + \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now1.fs new file mode 100644 index 00000000000..e81ce47bda6 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now1.fs @@ -0,0 +1,21 @@ +module now1 + +// +open System +open System.Globalization + +let localDate = DateTime.Now +let cultureNames = + [ "en-US"; "en-GB"; "fr-FR"; "de-DE"; "ru-RU" ] + +for cultureName in cultureNames do + let culture = CultureInfo cultureName + printfn $"{cultureName}: {localDate.ToString culture}" + +// The example displays the following output: +// en-US: 6/19/2015 10:03:06 AM +// en-GB: 19/06/2015 10:03:06 +// fr-FR: 19/06/2015 10:03:06 +// de-DE: 19.06.2015 10:03:06 +// ru-RU: 19.06.2015 10:03:06 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now2.fs new file mode 100644 index 00000000000..f02b1211a1e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now2.fs @@ -0,0 +1,38 @@ +module now2 + +// +open System +open System.Globalization + +let localDate = DateTime.Now +let utcDate = DateTime.UtcNow +let cultureNames = + [ "en-US"; "en-GB"; "fr-FR"; "de-DE"; "ru-RU" ] + +for cultureName in cultureNames do + let culture = CultureInfo cultureName + printfn $"{culture.NativeName}:" + printfn $" Local date and time: {localDate.ToString culture}, {localDate.Kind:G}" + printfn $" UTC date and time: {utcDate.ToString culture}, {utcDate.Kind:G}\n" + +// The example displays the following output: +// English (United States): +// Local date and time: 6/19/2015 10:35:50 AM, Local +// UTC date and time: 6/19/2015 5:35:50 PM, Utc +// +// English (United Kingdom): +// Local date and time: 19/06/2015 10:35:50, Local +// UTC date and time: 19/06/2015 17:35:50, Utc +// +// français (France): +// Local date and time: 19/06/2015 10:35:50, Local +// UTC date and time: 19/06/2015 17:35:50, Utc +// +// Deutsch (Deutschland): +// Local date and time: 19.06.2015 10:35:50, Local +// UTC date and time: 19.06.2015 17:35:50, Utc +// +// русский (Россия): +// Local date and time: 19.06.2015 10:35:50, Local +// UTC date and time: 19.06.2015 17:35:50, Utc +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/fs.fsproj new file mode 100644 index 00000000000..c069a6567be --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/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.datetime.timeofday/fs/timeofday1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/timeofday1.fs new file mode 100644 index 00000000000..7d33f5497ca --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/timeofday1.fs @@ -0,0 +1,26 @@ +// +open System + +let dates = + [ DateTime.Now + DateTime(2013, 9, 14, 9, 28, 0) + DateTime(2011, 5, 28, 10, 35, 0) + DateTime(1979, 12, 25, 14, 30, 0) ] + +for date in dates do + printfn $"Day: {date.Date:d} Time: {date.TimeOfDay:g}" + printfn $"Day: {date:d} Time: {date:t}\n" + +// The example displays output like the following: +// Day: 7/25/2012 Time: 10:08:12.9713744 +// Day: 7/25/2012 Time: 10:08 AM +// +// Day: 9/14/2013 Time: 9:28:00 +// Day: 9/14/2013 Time: 9:28 AM +// +// Day: 5/28/2011 Time: 10:35:00 +// Day: 5/28/2011 Time: 10:35 AM +// +// Day: 12/25/1979 Time: 14:30:00 +// Day: 12/25/1979 Time: 2:30 PM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/fs.fsproj new file mode 100644 index 00000000000..172229428e7 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/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.datetime.tolocaltime/fs/tolocaltime1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs new file mode 100644 index 00000000000..cba9463f92e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs @@ -0,0 +1,13 @@ +// +open System + +let date1 = DateTime(2010, 3, 14, 2, 30, 0, DateTimeKind.Local) +printfn $"Invalid time: {TimeZoneInfo.Local.IsInvalidTime date1}" +let utcDate1 = date1.ToUniversalTime() +let date2 = utcDate1.ToLocalTime() +printfn $"{date1} --> {date2}" + +// The example displays the following output: +// Invalid time: True +// 3/14/2010 2:30:00 AM --> 3/14/2010 3:30:00 AM +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/fs.fsproj new file mode 100644 index 00000000000..c6a16948727 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/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.datetime.tolongtimestring/fs/sls.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/sls.fs new file mode 100644 index 00000000000..7611838f6f3 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/sls.fs @@ -0,0 +1,50 @@ +// +open System +open System.Threading +open System.Globalization + +// Create a list of culture names. +let names = [ "en-US"; "en-GB"; "fr-FR"; "de-DE" ] + +// Initialize a DateTime object. +let dateValue = DateTime(2013, 5, 28, 10, 30, 15) + +// Iterate the array of culture names. +for name in names do + // Change the culture of the current thread. + Thread.CurrentThread.CurrentCulture <- CultureInfo.CreateSpecificCulture name + // Display the name of the current culture and the date. + printfn $"Current culture: {CultureInfo.CurrentCulture.Name}" + printfn $"Date: {dateValue:G}" + + // Display the long time pattern and the long time. + printfn $"Long time pattern: '{DateTimeFormatInfo.CurrentInfo.LongTimePattern}'" + printfn $"Long time with format string: {dateValue:T}" + printfn $"Long time with ToLongTimeString: {dateValue.ToLongTimeString()}\n" + + +// The example displays the following output: +// Current culture: en-US +// Date: 5/28/2013 10:30:15 AM +// Long time pattern: 'h:mm:ss tt' +// Long time with format string: 10:30:15 AM +// Long time with ToLongTimeString: 10:30:15 AM +// +// Current culture: en-GB +// Date: 28/05/2013 10:30:15 +// Long time pattern: 'HH:mm:ss' +// Long time with format string: 10:30:15 +// Long time with ToLongTimeString: 10:30:15 +// +// Current culture: fr-FR +// Date: 28/05/2013 10:30:15 +// Long time pattern: 'HH:mm:ss' +// Long time with format string: 10:30:15 +// Long time with ToLongTimeString: 10:30:15 +// +// Current culture: de-DE +// Date: 28.05.2013 10:30:15 +// Long time pattern: 'HH:mm:ss' +// Long time with format string: 10:30:15 +// Long time with ToLongTimeString: 10:30:15 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs new file mode 100644 index 00000000000..4991e47d19a --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.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 = DateTime(1867, 1, 1) + +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.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs new file mode 100644 index 00000000000..c76ea4f0921 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs @@ -0,0 +1,27 @@ +module argumentoutofrangeexception2 + +// +open System +open System.Globalization +open System.Threading + +let date1 = DateTime(550, 1, 1) +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.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs new file mode 100644 index 00000000000..12d2c38c70e --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs @@ -0,0 +1,27 @@ +module argumentoutofrangeexception3 + +// +open System +open System.Globalization +open System.Threading + +let date1 = DateTime(1550, 7, 21) +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.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs new file mode 100644 index 00000000000..6dea081ba58 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs @@ -0,0 +1,19 @@ +module argumentoutofrangeexception4 + +// +open System +open System.Globalization + +let arSA = CultureInfo "ar-SA" +arSA.DateTimeFormat.Calendar <- UmAlQuraCalendar() +let date1 = DateTime(1890, 9, 10) + +try + date1.ToString("d", arSA) + |> printfn "%s" +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 5/13/2029 +// \ No newline at end of file diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/fs.fsproj new file mode 100644 index 00000000000..9d4d3487b96 --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.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.datetime.touniversaltime/fs/fs.fsproj b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/fs.fsproj new file mode 100644 index 00000000000..902c2e2d2fa --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/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.datetime.touniversaltime/fs/touniversaltime.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs new file mode 100644 index 00000000000..281d67bf83b --- /dev/null +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs @@ -0,0 +1,16 @@ +// +open System + +let date1 = DateTime(2006, 3, 21, 2, 0, 0) + +printfn $"{date1.ToUniversalTime()}" +printfn $"{TimeZoneInfo.ConvertTimeToUtc date1}" + +let tz = TimeZoneInfo.FindSystemTimeZoneById "Pacific Standard Time" +printfn $"{TimeZoneInfo.ConvertTimeToUtc(date1, tz)}" + +// The example displays the following output on Windows XP systems: +// 3/21/2006 9:00:00 AM +// 3/21/2006 9:00:00 AM +// 3/21/2006 10:00:00 AM +// \ No newline at end of file diff --git a/xml/System/DateTime.xml b/xml/System/DateTime.xml index 6a0823b468c..3ec910e5b31 100644 --- a/xml/System/DateTime.xml +++ b/xml/System/DateTime.xml @@ -166,7 +166,7 @@ Time values are measured in 100-nanosecond units called ticks. A particular date > [!NOTE] > If you are working with a ticks value that you want to convert to some other time interval, such as minutes or seconds, you should use the , , , , or constant to perform the conversion. For example, to add the number of seconds represented by a specified number of ticks to the component of a value, you can use the expression `dateValue.Second + nTicks/Timespan.TicksPerSecond`. -You can view the source for the entire set of examples from this article in either [Visual Basic](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/visualbasic/System.DateTime/) or [C#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/csharp/System.DateTime/) from the docs repository on GitHub. +You can view the source for the entire set of examples from this article in either [Visual Basic](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/visualbasic/System.DateTime/), [F#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/fsharp/System.DateTime/), or [C#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/csharp/System.DateTime/) from the docs repository on GitHub. > [!NOTE] > An alternative to the structure for working with date and time values in particular time zones is the structure. The structure stores date and time information in a private field and the number of minutes by which that date and time differs from UTC in a private field. This makes it possible for a value to reflect the time in a particular time zone, whereas a value can unambiguously reflect only UTC and the local time zone's time. For a discussion about when to use the structure or the structure when working with date and time values, see [Choosing Between DateTime, DateTimeOffset, TimeSpan, and TimeZoneInfo](/dotnet/standard/datetime/choosing-between-datetime). @@ -189,12 +189,14 @@ You call any of the overloads of the constructor that spe :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Instantiation.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Instantiation.fs" id="Snippet1"::: You invoke the `DateTime` structure's implicit parameterless constructor when you want a `DateTime` initialized to its default value. (For details on the implicit parameterless constructor of a value type, see [Value Types](/dotnet/csharp/language-reference/keywords/value-types).) Some compilers also support declaring a value without explicitly assigning a value to it. Creating a value without an explicit initialization also results in the default value. The following example illustrates the implicit parameterless constructor in C# and Visual Basic, as well as a declaration without assignment in Visual Basic. :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb" id="Snippet5"::: :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Instantiation.cs" interactive="try-dotnet-method" id="Snippet5"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Instantiation.fs" id="Snippet5"::: #### Assigning a computed value @@ -203,6 +205,7 @@ You can assign the object a date and time value returned :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb" id="Snippet3"::: :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Instantiation.cs" id="Snippet3"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Instantiation.fs" id="Snippet3"::: #### Parsing a string that represents a DateTime @@ -211,6 +214,7 @@ The , , :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Instantiation.vb" id="Snippet4"::: :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Instantiation.cs" id="Snippet4"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Instantiation.fs" id="Snippet4"::: The and methods indicate whether a string is a valid representation of a value and, if it is, performs the conversion. @@ -229,30 +233,35 @@ The appearance of date and time values is dependent on culture, international st :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/StringFormat.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet1"::: You may need to format dates in a specific culture to support web scenarios where the server may be in a different culture from the client. You specify the culture using the method to create the short date and long time representation in a specific culture. The following example uses the method to display the date and time using the short date and long time pattern for the fr-FR culture. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet2"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/StringFormat.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet2"::: Other applications may require different string representations of a date. The method returns the string representation defined by a standard or custom format specifier using the formatting conventions of the current culture. The following example uses the method to display the full date and time pattern for the en-US culture, the current culture on the computer on which the example was run. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" id="Snippet3"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/StringFormat.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet3"::: Finally, you can specify both the culture and the format using the method. The following example uses the method to display the full date and time pattern for the fr-FR culture. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet4"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/StringFormat.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet4"::: The overload can also be used with a custom format string to specify other formats. The following example shows how to format a string using the [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format often used for web services. The Iso 8601 format does not have a corresponding standard format string. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/StringFormat.cs" interactive="try-dotnet-method" id="Snippet5"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/StringFormat.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/StringFormat.vb" id="Snippet5"::: For more information about formatting values, see [Standard Date and Time Format Strings](/dotnet/standard/base-types/standard-date-and-time-format-strings) and [Custom Date and Time Format Strings](/dotnet/standard/base-types/custom-date-and-time-format-strings). @@ -269,18 +278,21 @@ You use the or :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Parsing.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Parsing.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Parsing.vb" id="Snippet1"::: You use the and methods to convert a string that must match a particular format or formats to a value. You specify one or more date and time format strings as a parameter to the parsing method. The following example uses the method to convert strings that must be either in a "yyyyMMdd" format or a "HHmmss" format to values. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Parsing.cs" id="Snippet2"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Parsing.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Parsing.vb" id="Snippet2"::: One common use for is to convert a string representation from a web service, usually in [ISO 8601](https://www.iso.org/iso-8601-date-and-time-format.html) standard format. The following code shows the correct format string to use: :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Parsing.cs" interactive="try-dotnet-method" id="Snippet3"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Parsing.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Parsing.vb" id="Snippet3"::: If a string cannot be parsed, the and methods throw an exception. The and methods return a value that indicates whether the conversion succeeded or failed. You should use the or methods in scenarios where performance is important. The parsing operation for date and time strings tends to have a high failure rate, and exception handling is expensive. Use these methods if strings are input by users or coming from an unknown source. @@ -308,6 +320,7 @@ The following example illustrates the dependence of current date and time values :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Resolution.cs" interactive="try-dotnet-method" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Resolution.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Resolution.vb" id="Snippet1"::: ### DateTime operations @@ -352,18 +365,21 @@ A culture's current calendar is used in all formatting operations for that cultu :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Calendar.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Calendar.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Calendar.vb" id="Snippet1"::: A culture's current calendar is also used in all parsing operations for that culture, as the following example shows. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Calendar.cs" id="Snippet2"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Calendar.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Calendar.vb" id="Snippet2"::: You instantiate a value using the date and time elements (number of the year, month, and day) of a specific calendar by calling a [DateTime constructor](xref:System.DateTime.%23ctor%2A) that includes a `calendar` parameter and passing it a object that represents that calendar. The following example uses the date and time elements from the calendar. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Calendar.cs" id="Snippet3"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Calendar.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Calendar.vb" id="Snippet3"::: constructors that do not include a `calendar` parameter assume that the date and time elements are expressed as units in the Gregorian calendar. @@ -372,12 +388,14 @@ All other properties and methods use the Gregorian calend :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Calendar.cs" id="Snippet4"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Calendar.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Calendar.vb" id="Snippet4"::: The structure includes a property that returns the day of the week in the Gregorian calendar. It does not include a member that allows you to retrieve the week number of the year. To retrieve the week of the year, call the individual calendar's method. The following example provides an illustration. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Calendar.cs" id="Snippet5"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Calendar.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Calendar.vb" id="Snippet5"::: For more information on dates and calendars, see [Working with Calendars](/dotnet/standard/datetime/working-with-calendars). @@ -405,6 +423,7 @@ To successfully restore values that are persisted as stri :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet1"::: To round-trip values successfully, follow these steps: @@ -421,6 +440,7 @@ The following example uses the invariant culture and the "O" standard format str :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet2"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet2"::: #### Persisting values as integers @@ -441,6 +461,7 @@ The following example persists an array of values as inte :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet3"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet3"::: @@ -452,12 +473,14 @@ The following example uses the cla :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet4"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet4"::: The previous example doesn't include time information. If a value represents a moment in time and is expressed as a local time, convert it from local time to UTC before serializing it by calling the method. After you deserialize it, convert it from UTC to local time by calling the method. The following example uses the class to serialize data on a system in the U.S. Pacific Standard Time zone and to deserialize it on a system in the U.S. Central Standard zone. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet5"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet5"::: @@ -467,19 +490,22 @@ The previous examples all assumed that values are express :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/DateWithTimeZone.cs" id="Snippet6"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/DateWithTimeZone.fs" id="Snippet6"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/DateWithTimeZone.vb" id="Snippet6"::: > [!IMPORTANT] -> The `DateWithTimeZone` structure is used in the next two examples, which serialize and deserialize an array of `DateWithTimeZone` objects. You can view the source for the entire set of examples from this article in either [Visual Basic](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/visualbasic/System.DateTime/) or [C#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/csharp/System.DateTime/) from the docs repository on GitHub. +> The `DateWithTimeZone` structure is used in the next two examples, which serialize and deserialize an array of `DateWithTimeZone` objects. You can view the source for the entire set of examples from this article in either [Visual Basic](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/visualbasic/System.DateTime/), [F#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/fsharp/System.DateTime/), or [C#](https://github.com/dotnet/dotnet-api-docs/tree/main/samples/snippets/csharp/System.DateTime/) from the docs repository on GitHub. By using the `DateWithTimeZone` structure, you can then persist date and time along with time zone information. The following example uses the class to serialize an array of `DateWithTimeZone` objects. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet7"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet7"::: The following example then calls the method to deserialize it. :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/Persistence.cs" id="Snippet8"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/Persistence.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/Persistence.vb" id="Snippet8"::: ### DateTime vs. TimeSpan @@ -496,6 +522,7 @@ The following example demonstrates how to compare roughly equivalent :::code language="csharp" source="~/samples/snippets/csharp/System.DateTime/DateTimeComparisons.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/System.DateTime/DateTimeComparisons.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/System.DateTime/DateTimeComparisons.vb" id="Snippet1"::: ### COM interop considerations @@ -595,6 +622,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/datetime.ctor_Int64/CPP/ticks.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/datetime.ctor_Int64/CS/ticks.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/datetime.ctor_Int64/FS/ticks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/datetime.ctor_Int64/VB/ticks.vb" id="Snippet1"::: ]]> @@ -712,6 +740,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the constructor to instantiate a value. The example also illustrates that this overload creates a value whose time component equals midnight (or 0:00). :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet1"::: ]]> @@ -786,6 +815,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example calls the constructor twice to instantiate two values. The first call instantiates a value by using a object. Because the Persian calendar cannot be designated as the default calendar for a culture, displaying a date in the Persian calendar requires individual calls to its , , and methods. The second call to the constructor instantiates a value by using a object. The example changes the current culture to Arabic (Syria) and changes the current culture's default calendar to the Hijri calendar. Because Hijri is the current culture's default calendar, the method uses it to format the date. When the previous current culture (which is English (United States) in this case) is restored, the method uses the current culture's default Gregorian calendar to format the date. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample2.vb" id="Snippet2"::: ]]> @@ -870,6 +900,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the constructor to instantiate a value. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet3"::: ]]> @@ -961,6 +992,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the constructor to instantiate a value. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet7"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs" id="Snippet7"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet7"::: ]]> @@ -1055,6 +1087,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example calls the constructor twice to instantiate two values. The first call instantiates a value by using a object. Because the Persian calendar cannot be designated as the default calendar for a culture, displaying a date in the Persian calendar requires individual calls to its , , and methods. The second call to the constructor instantiates a value by using a object. The example changes the current culture to Arabic (Syria) and changes the current culture's default calendar to the Hijri calendar. Because Hijri is the current culture's default calendar, the method uses it to format the date. When the previous current culture (which is English (United States) in this case) is restored, the method uses the current culture's default Gregorian calendar to format the date. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample4.cs" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample4.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample4.vb" id="Snippet4"::: ]]> @@ -1153,6 +1186,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the constructor to instantiate a value. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet5"::: ]]> @@ -1251,6 +1285,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the constructor to instantiate a value. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample1.cs" interactive="try-dotnet-method" id="Snippet8"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample1.fs" id="Snippet8"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample1.vb" id="Snippet8"::: ]]> @@ -1353,6 +1388,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example calls the constructor twice to instantiate two values. The first call instantiates a value by using a object. Because the Persian calendar cannot be designated as the default calendar for a culture, displaying a date in the Persian calendar requires individual calls to its , , and methods. The second call to the constructor instantiates a value by using a object. The example changes the current culture to Arabic (Syria) and changes the current culture's default calendar to the Hijri calendar. Because Hijri is the current culture's default calendar, the method uses it to format the date. When the previous current culture (which is English (United States) in this case) is restored, the method uses the current culture's default Gregorian calendar to format the date. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample6.cs" id="Snippet6"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample6.fs" id="Snippet6"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample6.vb" id="Snippet6"::: ]]> @@ -1456,6 +1492,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example calls the constructor twice to instantiate two values. The first call instantiates a value by using a object. Because the Persian calendar cannot be designated as the default calendar for a culture, displaying a date in the Persian calendar requires individual calls to its , , and methods. The second call to the constructor instantiates a value by using a object. The example changes the current culture to Arabic (Syria) and changes the current culture's default calendar to the Hijri calendar. Because Hijri is the current culture's default calendar, the method uses it to format the date. When the previous current culture (which is English (United States) in this case) is restored, the method uses the current culture's default Gregorian calendar to format the date. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.constructor/cs/ctorexample9.cs" id="Snippet9"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.constructor/fs/ctorexample9.fs" id="Snippet9"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.constructor/vb/ctorexample9.vb" id="Snippet9"::: ]]> @@ -1551,6 +1588,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.Add/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Add/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Add/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Add/VB/class1.vb" id="Snippet1"::: ]]> @@ -1622,6 +1660,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.AddDays/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.AddDays/CS/class1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.AddDays/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.AddDays/VB/class1.vb" id="Snippet1"::: ]]> @@ -1690,6 +1729,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the method to add a number of whole and fractional values to a date and time. It also illustrates the loss of precision caused by passing the method a value that includes a fractional component. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.AddHours/cs/AddHours1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.AddHours/fs/AddHours1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.AddHours/vb/AddHours1.vb" id="Snippet1"::: ]]> @@ -1757,6 +1797,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the method to add one millisecond and 1.5 milliseconds to a value. It then displays each new value and displays the difference between it and the original value. The difference is displayed both as a time span and as a number of ticks. The example makes it clear that one millisecond equals 10,000 ticks. It also shows that fractional milliseconds are rounded before performing the addition; the value that results from adding 1.5 milliseconds to the original date is 2 milliseconds greater than the original date. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/cs/addmilliseconds2.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmilliseconds/fs/addmilliseconds2.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.addmilliseconds/vb/addmilliseconds2.vb" id="Snippet1"::: ]]> @@ -1825,6 +1866,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.datetime.addminutes/cpp/addminutes1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.addminutes/cs/addminutes1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addminutes/fs/addminutes1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.addminutes/vb/addminutes1.vb" id="Snippet1"::: ]]> @@ -1892,6 +1934,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example adds between zero and fifteen months to the last day of December, 2015. In this case, the AddMonths method returns the date of the last day of each month, and successfully handles leap years. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.addmonths/cs/addmonths1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addmonths/fs/addmonths1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.addmonths/vb/addmonths1.vb" id="Snippet1"::: ]]> @@ -1961,6 +2004,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example uses the method to add 30 seconds and the number of seconds in one day to a value. It then displays each new value and displays the difference between it and the original value. The difference is displayed both as a time span and as a number of ticks. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.addseconds/cs/addseconds1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addseconds/fs/addseconds1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.addseconds/vb/addseconds1.vb" id="Snippet1"::: ]]> @@ -2085,6 +2129,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example illustrates using the method with a value that represents a leap year day. It displays the date for the fifteen years prior to and the fifteen years that follow February 29, 2000. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.addyears/cs/addyears1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.addyears/fs/addyears1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.addyears/vb/addyears1.vb" id="Snippet1"::: ]]> @@ -2168,6 +2213,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.compare/cs/compare1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.compare/fs/compare1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.compare/vb/compare1.vb" id="Snippet1"::: ]]> @@ -2278,6 +2324,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example instantiates three objects, one that represents today's date, another that represents the date one year previously, and a third that represents the date one year in the future. It then calls the method and displays the result of the comparison. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo.2/CS/CompareTo_CS1_24564.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo.2/FS/CompareTo_CS1_24564.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo.2/VB/CompareTo_VB1_24564.vb" id="Snippet1"::: ]]> @@ -2364,6 +2411,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.CompareTo/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.CompareTo/CS/class1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.CompareTo/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.CompareTo/VB/class1.vb" id="Snippet1"::: ]]> @@ -2433,6 +2481,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Date/cpp/date1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Date/cs/Date1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Date/fs/Date1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Date/vb/Date1.vb" id="Snippet1"::: ]]> @@ -2484,11 +2533,13 @@ The behavior of the .NET Framework and COM means that if your application round- The property always returns the day of the month in the Gregorian calendar, even if the current value was instantiated using some other calendar or if the current culture's default calendar is not the Gregorian calendar. To retrieve the day of the month of a particular date using some other calendar, call that calendar's method. The following example uses both the property and the method to retrieve the day of the month for a value that is instantiated using the Hijri calendar. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Day/cs/Day1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Day/vb/Day1.vb" id="Snippet1"::: Similarly, the following example uses both the property and the method to retrieve the day of the month when the current culture is ar-SA, which uses Hijri as its default calendar. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Day/cs/Day2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Day/fs/Day2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Day/vb/Day2.vb" id="Snippet2"::: ## Examples @@ -2496,6 +2547,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Minute etc/VB/class1.vb" id="Snippet1"::: ]]> @@ -2561,6 +2613,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.DayOfWeek/CPP/dow.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.DayOfWeek/CS/dow.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DayOfWeek/FS/dow.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.DayOfWeek/VB/dow.vb" id="Snippet1"::: ]]> @@ -2617,6 +2670,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example displays the day of the year of December 31 for the years 2010-2020 in the Gregorian calendar. Note that the example shows that December 31 is the 366th day of the year in leap years. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.dayofyear/cs/dayofyear2.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.dayofyear/fs/dayofyear2.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.dayofyear/vb/dayofyear2.vb" id="Snippet1"::: ]]> @@ -2683,11 +2737,13 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.DaysInMonth/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.DaysInMonth/CS/class1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.DaysInMonth/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.DaysInMonth/VB/class1.vb" id="Snippet1"::: The following example displays the number of days in each month of a year specified in an integer array. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/cs/daysinmonth3.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.daysinmonth/fs/daysinmonth3.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.daysinmonth/vb/daysinmonth3.vb" id="Snippet1"::: ]]> @@ -2772,6 +2828,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/cs/sample.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/sample.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/vb/sample.vb" id="Snippet1"::: ]]> @@ -2837,6 +2894,7 @@ The behavior of the .NET Framework and COM means that if your application round- The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/cs/sample.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/fs/sample.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Equals-Instance/vb/sample.vb" id="Snippet1"::: ]]> @@ -2903,6 +2961,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.Equals/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Equals/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Equals/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Equals/VB/class1.vb" id="Snippet1"::: ]]> @@ -2974,6 +3033,7 @@ The behavior of the .NET Framework and COM means that if your application round- For example, the transition from standard time to daylight saving time occurs in the Pacific Time zone of the United States on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a binary value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.frombinary/cs/frombinary1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/frombinary1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.frombinary/vb/frombinary1.vb" id="Snippet1"::: ## Version Considerations @@ -3047,6 +3107,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.FromFileTime/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.FromFileTime/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.FromFileTime/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.FromFileTime/VB/class1.vb" id="Snippet1"::: ]]> @@ -3063,6 +3124,7 @@ The behavior of the .NET Framework and COM means that if your application round- For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/cs/fromfiletime1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: @@ -3264,6 +3326,7 @@ The behavior of the .NET Framework and COM means that if your application round- :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.GetDateTimeFormats/VB/class1.vb" id="Snippet1"::: The example displays the following output: @@ -3468,6 +3531,7 @@ July, 2009 The following example demonstrates the method. It displays the string representation of a date using the long date format specifier ("D") for the current culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CS/class1.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.GetDateTimeFormats/VB/class1.vb" id="Snippet3"::: ]]> @@ -3538,6 +3602,7 @@ July, 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CPP/class1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CS/class1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.GetDateTimeFormats/VB/class1.vb" id="Snippet2"::: The example displays the following output: @@ -3714,6 +3779,7 @@ juillet 2009 The following example demonstrates the method. It displays the string representations of a date using the short date format specifier ("d") for the fr-FR culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/CS/class1.cs" interactive="try-dotnet-method" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.GetDateTimeFormats/FS/class1.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.GetDateTimeFormats/VB/class1.vb" id="Snippet4"::: ]]> @@ -3872,6 +3938,7 @@ juillet 2009 The value of the property is always expressed using a 24-hour clock. To retrieve a string that represents the hour of a date and time using a 12-hour clock, call the or method with the "h" custom format specifier. For example: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Hour/cs/Hour1.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Hour/fs/Hour1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Hour/vb/Hour1.vb" id="Snippet1"::: @@ -3881,6 +3948,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Minute etc/VB/class1.vb" id="Snippet1"::: ]]> @@ -3998,6 +4066,7 @@ juillet 2009 The following example uses the method to determine which years between 1994 and 2014 are leap years. The example also illustrates the result when the method is used to add a year to a leap day. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/cs/IsLeapYear1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/fs/IsLeapYear1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.IsLeapYear/vb/IsLeapYear1.vb" id="Snippet1"::: ]]> @@ -4063,6 +4132,7 @@ juillet 2009 The following example uses the method to demonstrate how the property influences the and conversion methods. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Kind_Suite/cs/ks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Kind_Suite/vb/ks.vb" id="Snippet1"::: ]]> @@ -4121,6 +4191,7 @@ juillet 2009 The following example instantiates a object by passing its constructor an value that represents a number of ticks. Before invoking the constructor, the example ensures that this value is greater than or equal to `DateTime.MinValue.Ticks` and less than or equal to `DateTime.MaxValue.Ticks`. If not, it throws an . :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.MinValue/cs/MinValue.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.MinValue/vb/MinValue.vb" id="Snippet2"::: ]]> @@ -4179,16 +4250,19 @@ juillet 2009 You can display the string representation of the property by using the "fff" format specifier. For example, the following code displays a string that contains the number of milliseconds in a date and time to the console. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/cs/Millisecond.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Millisecond/vb/Millisecond.vb" id="Snippet1"::: You can also display the millisecond component together with the other components of a date and time value by using the "o" standard format specifier. For example: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/cs/Millisecond.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Millisecond/vb/Millisecond.vb" id="Snippet2"::: However, the "o" format specifier is intended less for displaying than for round-tripping or storing a value. You can also display milliseconds together with other date and time components by using a custom format string, as the following example shows. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/cs/Millisecond.cs" interactive="try-dotnet-method" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Millisecond/fs/Millisecond.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Millisecond/vb/Millisecond.vb" id="Snippet3"::: @@ -4198,6 +4272,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Minute etc/VB/class1.vb" id="Snippet1"::: ]]> @@ -4256,6 +4331,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Minute etc/VB/class1.vb" id="Snippet1"::: ]]> @@ -4308,6 +4384,7 @@ juillet 2009 defines the date and time that is assigned to an uninitialized variable. The following example illustrates this. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.MinValue/cs/MinValue.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.MinValue/vb/MinValue.vb" id="Snippet1"::: The and properties can be used to ensure that a value lies within the supported range before passing it to a constructor. The code in the Example section illustrates this usage. @@ -4318,6 +4395,7 @@ juillet 2009 The following example instantiates a object by passing its constructor an value that represents a number of ticks. Before invoking the constructor, the example ensures that this value is greater than or equal to `DateTime.MinValue.Ticks` and less than or equal to `DateTime.MaxValue.Ticks`. If not, it throws an . :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.MinValue/cs/MinValue.cs" interactive="try-dotnet-method" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.MinValue/fs/MinValue.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.MinValue/vb/MinValue.vb" id="Snippet2"::: ]]> @@ -4370,6 +4448,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Minute etc/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Minute etc/VB/class1.vb" id="Snippet1"::: ]]> @@ -4422,6 +4501,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.datetime.now/cpp/now1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.now/cs/now1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.now/vb/now1.vb" id="Snippet2"::: The resolution of this property depends on the system timer, which depends on the underlying operating system. It tends to be between 0.5 and 15 milliseconds. As a result, repeated calls to the property in a short time interval, such as in a loop, may return the same value. @@ -4440,6 +4520,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_System/system.datetime.now/cpp/now2.cpp" id="Snippet3"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.now/cs/now2.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.now/fs/now2.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.now/vb/now2.vb" id="Snippet3"::: ]]> @@ -4500,6 +4581,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime Operators/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime Operators/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime Operators/VB/class1.vb" id="Snippet1"::: ]]> @@ -4575,6 +4657,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime Operators/CPP/class1.cpp" id="Snippet2"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime Operators/CS/class1.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime Operators/FS/class1.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime Operators/VB/class1.vb" id="Snippet2"::: ]]> @@ -4972,6 +5055,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.Subtraction/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Subtraction/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Subtraction/VB/class1.vb" id="Snippet1"::: ]]> @@ -5038,6 +5122,7 @@ juillet 2009 :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.Subtraction/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Subtraction/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Subtraction/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Subtraction/VB/class1.vb" id="Snippet1"::: ]]> @@ -5122,6 +5207,7 @@ juillet 2009 The following example parses strings in each of these formats by using the formatting conventions of the current culture, which in this case is the en-US culture: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse6.cs"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse6.fs"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse6.vb"::: If the input string represents a leap day in a leap year in the calendar used by the parsing method (see [Parsing and cultural conventions](#Culture)), the method parses the string successfully. If the input string represents a leap day in a non-leap year, the method throws a . @@ -5195,11 +5281,13 @@ The `DateTime.Parse` overloads return a value whose property during a formatting and parsing operation by using the flag. The following example illustrates how the flag affects the parsing operation on values that are converted to strings by using the "o", "r", or "u" format specifier. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse5.cs" id="Snippet5"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse5.fs" id="Snippet5"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse5.vb" id="Snippet5"::: ## Examples @@ -5286,6 +5374,7 @@ The following example parses the string representation of several date and time It handles the exception that is thrown when the method tries to parse the string representation of a date and time by using some other culture's formatting conventions. It also shows how to successfully parse a date and time value that does not use the formatting conventions of the current culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse1.vb" id="Snippet1"::: ]]> @@ -5367,6 +5456,7 @@ This overload attempts to parse `s` by using the @@ -5498,6 +5588,7 @@ This method overload converts the date and time in `s` and sets the method and displays the value of the property of the resulting values. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Parse/cs/Parse4.cs" id="Snippet4"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Parse/fs/Parse4.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Parse/vb/Parse4.vb" id="Snippet4"::: ]]> @@ -5614,6 +5705,7 @@ The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/cs/ParseExact1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/ParseExact1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ParseExact/vb/ParseExact1.vb" id="Snippet1"::: ]]> @@ -5820,6 +5912,7 @@ The following example demonstrates the method. Note that the string " 5/01/2009 8:30 AM" cannot be parsed successfully when the `styles` parameter equals because leading spaces are not allowed by `format`. Additionally, the string "5/01/2009 09:00" cannot be parsed successfully with a `format` of "MM/dd/yyyyhh:mm" because the date string does not precede the month number with a leading zero, as `format` requires. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/cs/parseexact2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ParseExact/vb/parseexact2.vb" id="Snippet2"::: ]]> @@ -5943,6 +6036,7 @@ The following example demonstrates the method to ensure that a string in a number of possible formats can be successfully parsed . :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/cs/parseexact3.cs" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ParseExact/fs/parseexact3.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ParseExact/vb/parseexact3.vb" id="Snippet3"::: ]]> @@ -6028,6 +6122,7 @@ The following example demonstrates the @@ -6100,6 +6195,7 @@ The following example demonstrates the method to demonstrate how the property influences the and conversion methods. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Kind_Suite/cs/ks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Kind_Suite/vb/ks.vb" id="Snippet1"::: ]]> @@ -6188,6 +6284,7 @@ The following example demonstrates the @@ -6273,6 +6370,7 @@ The following example demonstrates the @@ -7232,6 +7330,7 @@ In general, the ticks represent the time according to the time zone specified by The following example uses the property to display the number of ticks that have elapsed since the beginning of the twenty-first century and to instantiate a object. The object is then used to display the elapsed time using several other time intervals. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Ticks/cs/Ticks.cs" interactive="try-dotnet-method" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Ticks/fs/Ticks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Ticks/vb/Ticks.vb" id="Snippet1"::: ]]> @@ -7296,6 +7395,7 @@ In general, the ticks represent the time according to the time zone specified by The following example displays the value of the property for an array of values. It also contrasts the return value with the string returned by the "t" standard format string in a composite formatting operation. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.timeofday/cs/timeofday1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.timeofday/fs/timeofday1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.timeofday/vb/timeofday1.vb" id="Snippet1"::: ]]> @@ -7362,6 +7462,7 @@ In general, the ticks represent the time according to the time zone specified by For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a binary value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.frombinary/cs/frombinary1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.frombinary/fs/frombinary1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.frombinary/vb/frombinary1.vb" id="Snippet1"::: ## Version Considerations @@ -7432,6 +7533,7 @@ In general, the ticks represent the time according to the time zone specified by The following example uses the property to retrieve the current date. It also illustrates how a value can be formatted using some of the standard date and time format strings. Note that the output produced by the third call to the method uses the g format specifier to include the time component, which is zero. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Today/cs/Today1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Today/fs/Today1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Today/vb/Today1.vb" id="Snippet1"::: ]]> @@ -7494,6 +7596,7 @@ In general, the ticks represent the time according to the time zone specified by :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.ToFileTime/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.ToFileTime/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToFileTime/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.ToFileTime/VB/class1.vb" id="Snippet1"::: ]]> @@ -7509,6 +7612,7 @@ In general, the ticks represent the time according to the time zone specified by For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to a long integer value by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/cs/fromfiletime1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.fromfiletime/fs/fromfiletime1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.fromfiletime/vb/fromfiletime1.vb" id="Snippet1"::: @@ -7644,11 +7748,13 @@ In general, the ticks represent the time according to the time zone specified by :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/CPP/class1.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/CS/class1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/FS/class1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.ToLocalTime ToUniversalTime/VB/class1.vb" id="Snippet1"::: The following example uses the method to demonstrate how the property influences the and conversion methods. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Kind_Suite/cs/ks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Kind_Suite/vb/ks.vb" id="Snippet1"::: ]]> @@ -7659,6 +7765,7 @@ In general, the ticks represent the time according to the time zone specified by For example, the transition from standard time to daylight saving time occurs in the U.S. Pacific Time zone on March 14, 2010, at 2:00 A.M., when the time advances by one hour, to 3:00 A.M. This hour interval is an invalid time, that is, a time interval that does not exist in this time zone. The following example shows that when a time that falls within this range is converted to UTC by the method and is then restored by the method, the original value is adjusted to become a valid time. You can determine whether a particular date and time value may be subject to modification by passing it to the method, as the example illustrates. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/cs/tolocaltime1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolocaltime/fs/tolocaltime1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tolocaltime/vb/tolocaltime1.vb" id="Snippet1"::: @@ -7724,6 +7831,7 @@ In general, the ticks represent the time according to the time zone specified by The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.ToShortLongString/cs/sls.cs" id="Snippet1"::: +:::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/sls.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.ToShortLongString/vb/sls.vb" id="Snippet1"::: ]]> @@ -7793,6 +7901,7 @@ The value of the current object is formatted using the pa The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/cs/sls.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tolongtimestring/fs/sls.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tolongtimestring/vb/sls.vb" id="Snippet1"::: ]]> @@ -7915,6 +8024,7 @@ The value of the current object is formatted using the pa The following example demonstrates the method. It also shows that the result of calling the method is identical to calling the method with "d" as the format parameter. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/cs/ToShortDateString.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/fs/ToShortDateString.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToShortDateString/vb/ToShortDateString.vb" id="Snippet1"::: ]]> @@ -7984,6 +8094,7 @@ The value of the current object is formatted using the pa The following example demonstrates the method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.ToShortLongString/cs/sls.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.ToShortLongString/fs/sls.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.ToShortLongString/vb/sls.vb" id="Snippet1"::: ]]> @@ -8067,6 +8178,7 @@ The value of the current object is formatted using the pa The following example illustrates how the string representation of a value returned by the method depends on the thread current culture. It changes the current culture to en-US, fr-FR, and ja-JP, and in each case calls the method to return the string representation of a date and time value using that culture. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString1.vb" id="Snippet1"::: ]]> @@ -8076,6 +8188,7 @@ The following example illustrates how the string representation of a 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.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception2.vb" id="Snippet2"::: @@ -8164,6 +8277,7 @@ The following example illustrates how the string representation of a objects that represent five different cultures. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString4.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString4.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString4.vb" id="Snippet3"::: ]]> @@ -8173,6 +8287,7 @@ The following example illustrates how the string representation of a 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.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception1.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception1.vb" id="Snippet1"::: @@ -8251,12 +8366,14 @@ The following example illustrates how the string representation of a value. The thread current culture for the example is en-US. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.ToString/cs/ToString2.cs" interactive="try-dotnet" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.ToString/fs/ToString2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.ToString/vb/ToString2.vb" id="Snippet2"::: ]]> @@ -8271,6 +8388,7 @@ The following example illustrates how the string representation of a 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.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception3.cs" interactive="try-dotnet" id="Snippet3"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception3.fs" id="Snippet3"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception3.vb" id="Snippet3"::: @@ -8358,12 +8476,14 @@ The following example illustrates how the string representation of a value using the invariant . :::code language="cpp" source="~/samples/snippets/cpp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CPP/source.cpp" id="Snippet1"::: :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/CS/source.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/FS/source.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_Classic/classic DateTime.ToString2 Example/VB/source.vb" id="Snippet1"::: ]]> @@ -8378,6 +8498,7 @@ The following example illustrates how the string representation of a 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.datetime.tostring.argumentoutofrangeexception/cs/datetime.tostring.argumentoutofrangeexception4.cs" interactive="try-dotnet" id="Snippet4"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/fs/datetime.tostring.argumentoutofrangeexception4.fs" id="Snippet4"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.tostring.argumentoutofrangeexception/vb/datetime.tostring.argumentoutofrangeexception4.vb" id="Snippet4"::: @@ -8459,11 +8580,13 @@ The following example illustrates how the string representation of a method to demonstrate how the property influences the and conversion methods. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Kind_Suite/cs/ks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Kind_Suite/vb/ks.vb" id="Snippet1"::: ]]> @@ -8476,6 +8599,7 @@ The following example illustrates how the string representation of a and methods on a Windows XP system in the U.S. Pacific Time zone. The first two method calls apply the current time zone adjustment rule (which went into effect in 2007) to a date in 2006. The current adjustment rule provides for the transition to daylight saving time on the second Sunday of March; the previous rule, which was in effect in 2006, provided for the transition to daylight saving time to occur on the first Sunday of April. Only the third method call accurately performs this historical date and time conversion. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/cs/touniversaltime.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.datetime.touniversaltime/fs/touniversaltime.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.datetime.touniversaltime/vb/touniversaltime.vb" id="Snippet1"::: @@ -8659,6 +8783,7 @@ The following example illustrates how the string representation of a @@ -8827,6 +8952,7 @@ The following example illustrates how the string representation of a method. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.TryParse/cs/tryparse2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParse/fs/tryparse2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.TryParse/vb/tryparse2.vb" id="Snippet2"::: ]]> @@ -9060,6 +9186,7 @@ The following example illustrates how the string representation of a method. Note that the string " 5/01/2009 8:30 AM" cannot be parsed successfully when the `styles` parameter equals because leading spaces are not allowed by `format`. Additionally, the string "5/01/2009 09:00" cannot be parsed successfully with a `format` of "MM/dd/yyyyhh:mm" because the date string does not precede the month number with a leading zero, as `format` requires. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/cs/TryParseExact1.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact1.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.TryParseExact/vb/TryParseExact1.vb" id="Snippet1"::: ]]> @@ -9177,6 +9304,7 @@ The following example illustrates how the string representation of a method to ensure that a string in a number of possible formats can be successfully parsed . :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/cs/TryParseExact2.cs" id="Snippet2"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs" id="Snippet2"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.TryParseExact/vb/TryParseExact2.vb" id="Snippet2"::: ]]> @@ -9290,6 +9418,7 @@ The following example illustrates how the string representation of a method to demonstrate how the property influences the and conversion methods. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR/DateTime.Kind_Suite/cs/ks.cs" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR/DateTime.Kind_Suite/fs/ks.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR/DateTime.Kind_Suite/vb/ks.vb" id="Snippet1"::: ]]> @@ -9343,6 +9472,7 @@ The following example illustrates how the string representation of a property returns the year of the current instance in the Gregorian calendar. It does not return the year using the default calendar of the current culture. To retrieve the year using a particular calendar, you can call that calendar's `GetYear` method, as the following code shows. :::code language="csharp" source="~/samples/snippets/csharp/VS_Snippets_CLR_System/system.DateTime.Year/cs/Year.cs" interactive="try-dotnet" id="Snippet1"::: + :::code language="fsharp" source="~/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.Year/fs/Year.fs" id="Snippet1"::: :::code language="vb" source="~/samples/snippets/visualbasic/VS_Snippets_CLR_System/system.DateTime.Year/vb/Year.vb" id="Snippet1"::: @@ -9352,6 +9482,7 @@ The following example illustrates how the string representation of a From 95da4a869105eca3050f6976e048bdb576e16987 Mon Sep 17 00:00:00 2001 From: albert-du <52804499+albert-du@users.noreply.github.com> Date: Tue, 4 Jan 2022 21:13:06 -0800 Subject: [PATCH 2/2] Add missing module declaration --- .../system.DateTime.TryParseExact/fs/TryParseExact2.fs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs index d3f0e0e03a8..714ec9be6ca 100644 --- a/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs +++ b/samples/snippets/fsharp/VS_Snippets_CLR_System/system.DateTime.TryParseExact/fs/TryParseExact2.fs @@ -1,4 +1,6 @@ -// +module TryParseExact2 + +// open System open System.Globalization