如何在C#中以mm / dd / yyyy格式获取今天的日期? [英] How do I get today's date in C# in mm/dd/yyyy format?
问题描述
我需要将字符串变量设置为今天的日期(最好不要年) ,但是一次要做一个更好的方法比一个月 - / - 一天。
BTW:我在美国,所以M / dd将是正确的,例如9月11日是9/11。
注意:kronoz的答案来自于讨论国际化,我认为这是非常好的提到,因为我可以'不要让它成为'接受'的答案。
DateTime.Now.ToString(M / d / yyyy);
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
How do I get today's date in C# in mm/dd/yyyy format?
I need to set a string variable to today's date (preferably without the year), but there's got to be a better way than building it month-/-day one piece at a time.
BTW: I'm in the US so M/dd would be correct, e.g. September 11th is 9/11.
Note: an answer from kronoz came in that discussed internationalization, and I thought it was awesome enough to mention since I can't make it an 'accepted' answer as well.
DateTime.Now.ToString("M/d/yyyy");
http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx
这篇关于如何在C#中以mm / dd / yyyy格式获取今天的日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!