Answers:
DateTime.Now.ToString("M/d/yyyy");
不必太过分学究,但是,如果您正在对代码进行国际化,那么拥有针对特定文化的简短日期的设施可能会更有用,例如:
using System.Globalization;
using System.Threading;
...
var currentCulture = Thread.CurrentThread.CurrentCulture;
try {
Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-us");
string shortDateString = DateTime.Now.ToShortDateString();
// Do something with shortDateString...
} finally {
Thread.CurrentThread.CurrentCulture = currentCulture;
}
尽管显然“ m / dd / yyyy”方法更加整洁!
DateTime.Now.ToString("dd/MM/yyyy");
如果您希望没有年份:
DateTime.Now.ToString("MM/DD");
DateTime.ToString()有很多很酷的格式字符串:
DateTime.Now.Date.ToShortDateString()
是特定于文化的。
最好坚持:
DateTime.Now.ToString("d/MM/yyyy");
DateTime.Now.Date.ToShortDateString()
我想这就是你要找的