DateTime.Parse怎么样给str指定格式

DateTime.Parse怎么样给str指定格式,第1张

面的示例说明 Parse 方法

[Visual Basic]
Dim strMyDateTime As String
strMyDateTime = "2/16/1992 12:15:12"

' myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec
Dim myDateTime As SystemDateTime
myDateTime = SystemDateTimeParse(strMyDateTime)

Dim format As New SystemGlobalizationCultureInfo("fr-FR", True)

' Reverse month and day to conform to a different format
Dim strMyDateTimeFrench As String
strMyDateTimeFrench = " 16/02/1992 12:15:12"

' myDateTimeFrench gets Feburary 16, 1992, 12 hours,
' 15 min and 12 sec
Dim myDateTimeFrench As SystemDateTime
myDateTimeFrench = SystemDateTimeParse( _
strMyDateTimeFrench, _
format, _
SystemGlobalization _
DateTimeStylesNoCurrentDateDefault)

Dim expectedFormats As String() = {"G", "g", "f", "F"}
' myDateTimeFrench gets Feburary 16, 1992, 12 hours,
' 15 min and 12 sec
myDateTimeFrench = SystemDateTimeParseExact( _
strMyDateTimeFrench, _
expectedFormats, _
format, _
SystemGlobalization _
DateTimeStylesAllowWhiteSpaces)

[C#]
string strMyDateTime = "2/16/1992 12:15:12";

// myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec
SystemDateTime myDateTime =
SystemDateTimeParse(strMyDateTime);

SystemIFormatProvider format =
new SystemGlobalizationCultureInfo("fr-FR", true);

// Reverse month and day to conform to a different format
string strMyDateTimeFrench = " 16/02/1992 12:15:12";

// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec
SystemDateTime myDateTimeFrench =
SystemDateTimeParse(strMyDateTimeFrench,
format,
SystemGlobalization
DateTimeStylesNoCurrentDateDefault);

string[] expectedFormats = {"G", "g", "f" ,"F"};
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec
myDateTimeFrench =
SystemDateTimeParseExact(strMyDateTimeFrench,
expectedFormats,
format,
SystemGlobalization
DateTimeStylesAllowWhiteSpaces);

[C++]
String strMyDateTime = S"2/16/1992 12:15:12";

// myDateTime gets Feburary 16, 1992, 12 hours, 15 min and 12 sec
System::DateTime myDateTime =
System::DateTime::Parse(strMyDateTime);

System::IFormatProvider format = new System::Globalization::CultureInfo(S"fr-FR", true);

// Reverse month and day to conform to a different format
String strMyDateTimeFrench = S" 16/02/1992 12:15:12";

// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec
System::DateTime myDateTimeFrench =
System::DateTime::Parse(strMyDateTimeFrench,
format,
System::Globalization::
DateTimeStyles::NoCurrentDateDefault);

String expectedFormats[] = {S"G", S"g", S"f" , S"F"};
// myDateTimeFrench gets Feburary 16, 1992, 12 hours,
// 15 min and 12 sec
myDateTimeFrench =
System::DateTime::ParseExact(strMyDateTimeFrench,
expectedFormats,
format,
System::Globalization::
DateTimeStyles::AllowWhiteSpaces);

欢迎分享,转载请注明来源:浪漫分享网

原文地址:https://hunlipic.com/meirong/6260805.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2023-09-06
下一篇2023-09-06

发表评论

登录后才能评论

评论列表(0条)

    保存