日期格式 [英] DateFormat
问题描述
我正在获取格式为"dd/mm/yyyy"的日期字符串.代码为DateTime.Today.ToShortDateString();
I am getting the date string in the format "dd/mm/yyyy" for the code DateTime.Today.ToShortDateString();
即使将区域设置更改为其他国家/地区.
Even if changed the regional settings to different country.
但我想将格式设为"mm/dd/yyyy".
But I would like to get the format as "mm/dd/yyyy". Where to change the settings.
推荐答案
希望这可以解决您的问题.
hope this solves your problem..
今天的DateTime = DateTime.Now;
DateTime today = DateTime.Now;
DateTimeFormatInfo dateFormat = 新 DateTimeFormatInfo();
DateTimeFormatInfo dateFormat = new DateTimeFormatInfo();
dateFormat.ShortDatePattern ="MM/dd/yyyy";
dateFormat.ShortDatePattern = "MM/dd/yyyy";
字符串 todayAsString = today.ToString("d",dateFormat);
string todayAsString = today.ToString("d",dateFormat);
这篇关于日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!