简体   繁体   English

将日期时间转换为WinForm中的短格式

[英]dateTime to short format in winform

I want to display date time like 01/08/11 , but i write this 我想显示日期时间,如01/08/11 ,但我这样写

string title_row = DateTime.Now.ToShortDateString();

and the result is 8/1/2011 how i can change the formt to 01/08/11 结果是2011年8月1日我如何将表格更改为01/08/11

How about? 怎么样?

DateTime.Now.ToString("dd/MM/yy")

, alternatively you should investigate Culture . 或者,您应该调查Culture

You can use the string format parameter of the ToString method to achieve any format you like, like this: 您可以使用ToString方法的字符串格式参数来实现所需的任何格式,如下所示:

string title_row = DateTime.Now.ToString("dd/MM/yy");
//01/08/11

For example using DateTime.Now.ToString("dd/MM/yyyy) 例如,使用DateTime.Now.ToString(“ dd / MM / yyyy)

Check http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx 检查http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx

DateTime.Now.ToString("dd/MM/yy"); should get you the required format 应该给你所需的格式

ToShortDateString() is governed by the culture settings and the display format is derived from the current culture, so to get it in the desired format pass in the appropriate formatting. ToShortDateString()由区域性设置控制,显示格式是从当前区域性派生的,因此要以所需格式获取它,并以适当的格式传递。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM