■■■

2016年4月5日火曜日

日付文字列からDateTimeに変換する方法

Microsoft Visual Studio: 242 Most Asked Questions on Microsoft Visual Studio - What You Need to Know (Success Secrets)
日付文字列からDateTimeに変換する方法
VB.NET
Dim s1 As String = "1992/2/16 12:15:12"
Dim dt1 As DateTime = DateTime.Parse(s1)
Console.WriteLine(dt1)

Dim s2 As String = "1992/2/16"
Dim dt2 As DateTime = DateTime.Parse(s2)
Console.WriteLine(dt2)

Dim s3 As String = "12:15:12"
Dim dt3 As DateTime = DateTime.Parse(s3)
Console.WriteLine(dt3)
Microsoft Visual Studio: 242 Most Asked Questions on Microsoft Visual Studio - What You Need to Know (Success Secrets)
C#
string s1 = "1992/2/16 12:15:12";
DateTime dt1 = DateTime.Parse(s1);
Console.WriteLine(dt1);

string s2 = "1992/2/16";
DateTime dt2 = DateTime.Parse(s2);
Console.WriteLine(dt2);

string s3 = "12:15:12";
DateTime dt3 = DateTime.Parse(s3);
Console.WriteLine(dt3);
Microsoft Visual Studio: 242 Most Asked Questions on Microsoft Visual Studio - What You Need to Know (Success Secrets)
■■■