如何将DateTimePicker日期设置为今天? [英] How can I set the DateTimePicker date to today?

查看:675
本文介绍了如何将DateTimePicker日期设置为今天?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是原始代码:

This is original code:

this.dateTimePicker1.Value = new System.DateTime(2012, 1, 11, 1, 7, 59, 0);


我想这样改变:


I want to change like this:

this.dateTimePicker1.Value = new System.DateTime.Now;

推荐答案

您已经拥有它.
this.dateTimePicker1.Value = System.DateTime.Now;
现在是静态方法,不能从实例中调用,这就是为什么您必须从语句中删除"new"的原因.
You already have it.
this.dateTimePicker1.Value = System.DateTime.Now;
.Now is a static method and cannot be called from an instance which is why you have to remove the "new" from the statement.


好吧,我知道,Now 是静态的属性,而不是
Ok, I see, Now is a static property so instead of
this.dateTimePicker1.Value = new System.DateTime.Now;


您应该使用


you should use

this.dateTimePicker1.Value = System.DateTime.Now;


这篇关于如何将DateTimePicker日期设置为今天?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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