Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ public static void Main()
foreach (string dateString in dateStrings)
{
DateTime convertedDate = DateTime.Parse(dateString);
Console.WriteLine("Converted {0} to {1} time {2}",
dateString,
convertedDate.Kind.ToString(),
convertedDate);
Console.WriteLine($"Converted {dateString} to {convertedDate.Kind} time {convertedDate}");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,11 @@ public static void Main()
Console.WriteLine(formattedDate);
DateTime roundtripDate = DateTime.Parse(formattedDate, null,
DateTimeStyles.RoundtripKind);
Console.WriteLine(" With RoundtripKind flag: {0} {1} time.",
roundtripDate, roundtripDate.Kind);
Console.WriteLine($" With RoundtripKind flag: {roundtripDate} {roundtripDate.Kind} time.");

DateTime noRoundtripDate = DateTime.Parse(formattedDate, null,
DateTimeStyles.None);
Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.",
noRoundtripDate, noRoundtripDate.Kind);
Console.WriteLine($" Without RoundtripKind flag: {noRoundtripDate} {noRoundtripDate.Kind} time.");
}
// The example displays the following output:
// 2008-09-15T09:30:41.7752486-07:00
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using System;

public class Example
{
public static void Main()
{
(string dateAsString, string description)[] 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" ) };

Console.WriteLine($"Today is {DateTime.Now:d}\n");

foreach (var item in dateInfo) {
Console.WriteLine($"{item.description + ":",-52} '{item.dateAsString}' --> {DateTime.Parse(item.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

Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@ Option Strict On
' <Snippet2>
Module Example
Public Sub Main()
Dim dateStrings() As String = {"2008-05-01T07:34:42-5:00", _
"2008-05-01 7:34:42Z", _
Dim dateStrings() As String = {"2008-05-01T07:34:42-5:00",
"2008-05-01 7:34:42Z",
"Thu, 01 May 2008 07:34:42 GMT"}

For Each dateString As String In dateStrings
Dim convertedDate As Date = Date.Parse(dateString)
Console.WriteLine("Converted {0} to {1} time {2}", _
dateString, _
convertedDate.Kind.ToString(), _
convertedDate)
For Each dateStr In dateStrings
Dim convertedDate As Date = Date.Parse(dateStr)
Console.WriteLine($"Converted {dateStr} to {convertedDate.Kind} time {convertedDate}")
Next
End Sub
End Module
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Module ParseDate
"10.01.2009 19:34", _
"10-1-2009 19:34" }
' Parse dates using each culture.
For Each culture As CultureInfo In cultures
For Each culture In cultures
Dim dateValue As Date
Console.WriteLine("Attempted conversions using {0} culture.", culture.Name)
For Each dateString As String In dateStrings
Expand Down
Original file line number Diff line number Diff line change
@@ -1,45 +1,38 @@
' Visual Basic .NET Document
Option Strict On

Imports System.Globalization

<Assembly: CLSCompliant(True)>
Module modMain
Public Module Class1
Public Sub Main()
' <Snippet5>
Dim formattedDates() As String = { "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 Each formattedDate As String In formattedDates
Console.WriteLine(formattedDate)
Dim roundtripDate As Date = Date.Parse(formattedDate, Nothing, _
DateTimeStyles.RoundtripKind)
Console.WriteLine(" With RoundtripKind flag: {0} {1} time.", _
roundtripDate, roundtripDate.Kind)
Dim noRoundtripDate As Date = Date.Parse(formattedDate, Nothing, _
DateTimeStyles.None)
Console.WriteLine(" Without RoundtripKind flag: {0} {1} time.", _
noRoundtripDate, noRoundtripDate.Kind)
Next
Dim 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 Each formattedDate In formattedDates
Console.WriteLine(formattedDate)
Dim roundtripDate = DateTime.Parse(formattedDate, Nothing,
DateTimeStyles.RoundtripKind)
Console.WriteLine($" With RoundtripKind flag: {roundtripDate} {roundtripDate.Kind} time.")
Dim noRoundtripDate = DateTime.Parse(formattedDate, Nothing, DateTimeStyles.None)
Console.WriteLine($" Without RoundtripKind flag: {noRoundtripDate} {noRoundtripDate.Kind} time.")
Next
' The example displays the following output:
' 2008-09-15T09:30:41.7752486-07:00
' With RounndtripKind flag: 9/15/2008 9:30:41 AM Local time.
' 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 RounndtripKind flag: 9/15/2008 9:30:41 AM Utc time.
' 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 RounndtripKind flag: 9/15/2008 9:30:41 AM Unspecified time.
' 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 RounndtripKind flag: 9/15/2008 6:30:41 AM Local time.
' 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 RounndtripKind flag: 9/15/2008 9:30:41 AM Utc time.
' With RoundtripKind flag: 9/15/2008 9:30:41 AM Utc time.
' Without RoundtripKind flag: 9/15/2008 2:30:41 AM Local time.
' </Snippet5>
End Sub
End Module

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@

Public Module Strings
Public Sub Main()
Dim dateInfo() As (dateAsString As String, description As String) =
{ ("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" ) }

Console.WriteLine($"Today is {Date.Now:d}{vbCrLf}")

For Each item in dateInfo
Console.WriteLine($"{item.description + ":",-52} '{item.dateAsString}' --> {DateTime.Parse(item.dateAsString)}")
Next
End Sub
End Module
' 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

Binary file not shown.
Loading