[英]c# datetimepicker : how do i get the date in the format? 1/1/2001
i am using winforms, c#, visual studio 2008 我正在使用winforms,c#,visual studio 2008
the format on the datetimepicker is set to short
which means that it will just display the date like this 1/1/2001
datetimepicker上的格式设置为short
,这意味着它只显示日期,如同1/1/2001
however, i am unable to just get that and NOT the time, 然而,我无法得到那个而不是时间,
for example this: 例如:
MessageBox.Show(dateTimePicker1.Value.Date.ToString());
gives me this: 给我这个:
11/4/2010 12:00:00AM
how do i get just 11/4/2010
? 我如何才能获得11/4/2010
?
For time call ToShortTimeString()
: 对于时间调用ToShortTimeString()
:
dateTimePicker1.Value.ToShortTimeString()
For date call ToShortDateString()
: 对于日期调用ToShortDateString()
:
dateTimePicker1.Value.ToShortDateString()
Example of both: 两者的例子:
Console.WriteLine(DateTime.Now.ToShortDateString());
Console.WriteLine(DateTime.Now.ToShortTimeString());
dateTimePicker1.Value.Date.ToString("M/d/yyyy")
.ToShortDateString()
也可以使用你所在地区的日期格式。
It should be possible to enter a format in the ToString method, like so: 应该可以在ToString方法中输入格式,如下所示:
Date.ToString("dM-yyyy"); Date.ToString( “DM-YYYY”);
You can use the format in ToString() function. 您可以在ToString()函数中使用该格式。 eg.- 例如。-
dateTimePicker1.Value.Date.ToString("dd/MM/yyyy") ==> gives value "04/11/2010" dateTimePicker1.Value.Date.ToString(“dd / MM / yyyy”)==>给出值“04/11/2010”
or 要么
dateTimePicker1.Value.Date.ToString("dd/MMM/yyyy") ==> gives value "04/Nov/2010" dateTimePicker1.Value.Date.ToString(“dd / MMM / yyyy”)==>给出值“04 / Nov / 2010”
however you may also use ToShortDateString() function it will return the date-format set in your computer system.... you may also change that from ControlPanel--> Region and Languages --> Date,Time format to "dd/MM/yyyy" to get "04/11/2010" etc. 但是你也可以使用ToShortDateString()函数它将返回计算机系统中设置的日期格式....你也可以将它从ControlPanel - > Region and Languages - > Date,Time格式更改为“dd / MM / yyyy“得到”04/11/2010“等
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.