本文介绍了领先的零日期格式C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有这个功能...
private string dateConvert(string datDate)
{
System.Globalization.CultureInfo cultEnGb = new System.Globalization.CultureInfo("en-GB");
System.Globalization.CultureInfo cultEnUs = new System.Globalization.CultureInfo("en-US");
DateTime dtGb = Convert.ToDateTime(datDate, cultEnGb.DateTimeFormat);
datDate = dtGb.ToString(cultEnUs.DateTimeFormat.ShortDatePattern);
return datDate;
}
但是我希望它与前导零仍然位于较低位数(1-9 )所以日期是11-09-2009(mm-dd-yyyy)...
But I want it with the leading zero still on lower digits (1-9) so the date is 11-09-2009 (mm-dd-yyyy)...
现在如果我没有转换它id使用string.Format( {0:d},dateVar)如何在转化中执行此操作?
Now If I wasn't converting it id use string.Format("{0:d}", dateVar) how do I do this in the conversion?
*****解决方案*****
使用稍微修改后的答案(即将呈现的答案)。
***** Solution *****
Used a slightly modified version of the answer below (i.e. one that would render).
Convert.ToDateTime(datDate).ToString("MM-dd-yyyy");
推荐答案
return dateTimeValue.ToString("MM-dd-yyyy");
这篇关于领先的零日期格式C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!