Asp.net 日期时间转换
我想将Asp.net 日期时间转换,asp.net,vb.net,datetime,Asp.net,Vb.net,Datetime,我想将mm/dd/yyyy转换为dd/mm/yyyy。 我的应用程序是asp.NET和VB。 我尝试了以下代码 DateTime.Parse(oldDate.ToString("dd\mm\yyyy")) 但我得到了一个错误: "The string was not recognized as a valid dateTime. There is an unknown word starting at index 2" 任何人都可以给出相应的代码吗?您应该转义\个字符。您应该转义\个字符。在
mm/dd/yyyy
转换为dd/mm/yyyy
。
我的应用程序是asp.NET和VB。
我尝试了以下代码
DateTime.Parse(oldDate.ToString("dd\mm\yyyy"))
但我得到了一个错误:
"The string was not recognized as a valid dateTime. There is an unknown word starting at index 2"
任何人都可以给出相应的代码吗?您应该转义\个字符。您应该转义\个字符。在VB中:
Dim dt As DateTime = _
DateTime.ParseExact(oldDate, "MM/dd/yyyy", CultureInfo.InvariantCulture)
' and then if you want to format it in dd/MM/yyyy format
Dim s As String = dt.ToString("dd/MM/yyyy")
在C#中:
在VB中:
在C#中:
如果oldDate是DateTime,那么您需要做的就是
Dim oldDate As DateTime = DateTime.Now
Dim odS As String 'old date as string
odS = oldDate.ToString("ddMMyyyy").Insert(4, "\").Insert(2, "\")
更改字符串格式不会更改日期时间。DateTime是数字,而不是字符串。如果oldDate是DateTime,那么您需要做的就是
Dim oldDate As DateTime = DateTime.Now
Dim odS As String 'old date as string
odS = oldDate.ToString("ddMMyyyy").Insert(4, "\").Insert(2, "\")
更改字符串格式不会更改日期时间。DateTime是数字,而不是字符串。这不是您的解决方案,但仅供参考:小心-小写的m是分钟;大写的M是月。这不是你的解决方案,但仅供参考:小心-小写的M是分钟;大写的M是月份。