转换DD / MM / YYYY以MM / DD / YYYY [英] Convert dd/MM/yyyy to MM/dd/YYYY
问题描述
我需要转换28/08/2012,以 MM / DD / YYYY
格式,这意味着2012年8月28日。结果
口怎么能这样做呢?
我使用下面的代码,但它抛出异常给我。
DateTime.ParseExact(28/08/2012,DDMMYYYY,CultureInfo.InvariantCulture)
但它抛出异常给我
块引用>
问题:
您日期中包含
/
分隔符(28/08/2012
),你不给,在你的日期字符串格式(DDMMYYYY
)。
解决方案:
这应该是
DD / MM / YYYY
。
本办法
DateTime.ParseExact(28/08/2012,DD / MM / YYYY,CultureInfo.InvariantCulture)
的ToString(MM / DD / YYYY,CultureInfo.InvariantCulture);
这样做,我们将获得一个DateTime对象与被转移到使用字符串<$您人口稠密日期后C $ C>的ToString()与所需的日期格式为:
MM / DD / YYYY
和可选的文化信息的CultureInfo .InvariantCulture
。I need to convert "28/08/2012" to
MM/dd/YYYY
format that means "08/28/2012".
How can I do that?I am using below code , but it threw exception to me.
DateTime.ParseExact("28/08/2012", "ddMMyyyy", CultureInfo.InvariantCulture)
解决方案but it threw exception to me
Problem:
Your date contains
/
seperator ("28/08/2012"
) and you are not giving that in your date string format ("ddMMyyyy"
).Solution:
It should be
"dd/MM/yyyy"
.This way
DateTime.ParseExact("28/08/2012", "dd/MM/yyyy", CultureInfo.InvariantCulture) .ToString("MM/dd/yyyy", CultureInfo.InvariantCulture);
After doing that we will receive a DateTime object with your populated dates which is transferred to string using
.ToString()
with desired date format"MM/dd/yyyy"
and optional culture infoCultureInfo.InvariantCulture
.这篇关于转换DD / MM / YYYY以MM / DD / YYYY的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!