c# datetimepicker:我如何以格式获取日期?2001 年 1 月 1 日 [英] c# datetimepicker : how do i get the date in the format? 1/1/2001

查看:83
本文介绍了c# datetimepicker:我如何以格式获取日期?2001 年 1 月 1 日的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 winforms、c#、visual studio 2008

i am using winforms, c#, visual studio 2008

datetimepicker 上的格式设置为 short 这意味着它只会显示这样的日期 1/1/2001

the format on the datetimepicker is set to short which means that it will just display the date like this 1/1/2001

但是,我无法做到这一点,而不是时间,

however, i am unable to just get that and NOT the time,

例如这个:

MessageBox.Show(dateTimePicker1.Value.Date.ToString());

给我这个:

11/4/2010 12:00:00AM

我如何获得 11/4/2010?

推荐答案

对于时间调用 ToShortTimeString():

dateTimePicker1.Value.ToShortTimeString()

对于日期调用ToShortDateString():

dateTimePicker1.Value.ToShortDateString()

两者的例子:

Console.WriteLine(DateTime.Now.ToShortDateString());
Console.WriteLine(DateTime.Now.ToShortTimeString());

这篇关于c# datetimepicker:我如何以格式获取日期?2001 年 1 月 1 日的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆