你怎么把日期格式从MM / dd / yyyy hh:mm:ss tt转换为dd / MM / yyyy hh:mm:ss tt [英] how do you convert the date format from MM/dd/yyyy hh:mm:ss tt to dd/MM/yyyy hh:mm:ss tt

查看:179
本文介绍了你怎么把日期格式从MM / dd / yyyy hh:mm:ss tt转换为dd / MM / yyyy hh:mm:ss tt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我想把日期转换为6/26/2013 10:33:21 AM到26/6/2013 10:33:上午21点。我试过这个:





Dim dDate As DateTime = DateTime.ParseExact(str,dd / MM / yyyy hh:mm:ss tt,CultureInfo.InvariantCulture)



但我得到格式异常。该字符串未被识别为有效的日期时间。



请帮忙。谢谢。

Hi All,

I am trying to convert the date 6/26/2013 10:33:21 AM to 26/6/2013 10:33:21 AM. I tried this :


Dim dDate As DateTime = DateTime.ParseExact(str, "dd/MM/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)

But i get a Format Exception. The string was not recognized as a valid Datetime.

Please help. Thanks.

推荐答案

只需用输入格式字符串中的dd切换MM,因为输入日期是月/日/年(Jun,26 th )format。
Just switch the MM with dd in input format string, since your input date is in month/day/year (Jun, 26th) format.


您试图使用想要的格式进行解析,而不是拥有的格式

尝试:

You were trying to parse with the format you wanted, not the format you have!
Try:
Dim dDate As DateTime = DateTime.ParseExact(str, "MM/dd/yyyy hh:mm:ss tt", CultureInfo.InvariantCulture)


DateTime变量不包含月份第一或第一类型数据。它们包含表示日期和时间的数值。从DateTime格式转换为String格式时,包含format字符串以告知 Format 函数如何创建结果字符串。



ParseExact要求字符数完全匹配。 Parse允许单个数字月或日。



DateTime variables do not contain month first or day first type data. They contain numeric value that represents the date and time. When converting from DateTime format to String format, a "format" string is included to tell the Format function how to create the resulting string.

ParseExact requires that the number of characters match exactly. Parse allows single digit month or day.

Dim str As String = "6/26/2013 10:33:21 AM"
Dim dDate As DateTime = DateTime.Parse(str, CultureInfo.InvariantCulture)
Dim strDayFirst As String = Format(dDate, "dd/MM/yyyy")





经过测试的Visual Basic .NET 2012


这篇关于你怎么把日期格式从MM / dd / yyyy hh:mm:ss tt转换为dd / MM / yyyy hh:mm:ss tt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆