日期格式问题,无法将字符串识别为有效的DateTime [英] date format issue, String was not recognized as a valid DateTime
本文介绍了日期格式问题,无法将字符串识别为有效的DateTime的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在从数据库获取日期,我想将日期转换为dd/MM/yyyy格式,
I am getting dates from database and i want to convert the date in dd/MM/yyyy format,
我正在尝试执行此操作,但它给我错误字符串未被识别为有效的DateTime."
I am trying this but it gives me error "String was not recognized as a valid DateTime."
DateTime pDate = DateTime.ParseExact("05/28/2013 12:00:00 AM", "dd/MM/yyyy", CultureInfo.InvariantCulture);
请让我知道如何将其转换为dd/MM/yyyy格式?
Please let me know how i can convert into dd/MM/yyyy format?
谢谢
推荐答案
2个步骤:
DateTime pDate = DateTime.ParseExact("05/28/2013 12:00:00 AM", "MM/dd/yyyy hh:mm:ss", CultureInfo.InvariantCulture);
return pDate.ToString("dd/MM/yyyy");
这篇关于日期格式问题,无法将字符串识别为有效的DateTime的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文