菜鸟求指导: 如何设置DateTimePicker中Value值

yangyi_33855 2011-02-22 12:58:50
部分代码如下:
//部分DateTimePicker控件编辑中的代码
//用于设置关机时间
this.SetupTime.CustomFormat = "00:00:00";
this.SetupTime.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.SetupTime.Value = new System.DateTime(2011, 2, 22,0, 0, 0, 0);
//用于设置关机日期
this.SetupDate.CustomFormat = "2011-2-22";
this.SetupDate.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
this.SetupDate.Value = new System.DateTime(2011, 2, 22);
//判断系统时间是否和设置的关机时间一致
if (CurrDate == SetupDate.ToString() && CurrTime == SetupTime.ToString())
CloseComputer();
其中:
string CurrDate = System.DateTime.Today.ToShortDateString();
string CurrTime = System.DateTime.Now.ToLongTimeString();

问题:设置好关机时间后,到了该时间还是不能关机。单步运行发现SetupTime和SetupDate的value都是 2011-2-11 00:00:00
请问各位高手我是不是在DateTimePicker控件中该如何设置,才能实现上面那个判断语句呢。
...全文
380 4 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
yangyi_33855 2011-02-22
  • 打赏
  • 举报
回复
我草,条条道路通罗马,作为一个菜鸟,对着书编都编不通,真郁闷啊。净信书不如无书啊,好,按照2楼大大昨天和今天给的指导,好好编了,练习练习,相信自己能学好的!
yangyi_33855 2011-02-22
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyq11 的回复:]
CustomFormat ="yyyy-MM-dd"
timer倒计时关机
或Process.Start("shutdown","-s -t 时间秒");
[/Quote]
我把设置关机时间中的CustomFormat格式改成 "yyyy-MM-dd"了,另外我用了一个Timer控件,
private void Timer1_Timer(object sender, EventArgs e)
{
string CurrDate = System.DateTime.Today.ToShortDateString();
string CurrTime = System.DateTime.Now.ToLongTimeString();

if(this.checkBox1.Checked==true)
{
if (CurrDate == SetupDate.ToString() && CurrTime == SetupTime.ToString())
CloseComputer();
}
}
戰國元帥 2011-02-22
  • 打赏
  • 举报
回复
用个Time控件
wuyq11 2011-02-22
  • 打赏
  • 举报
回复
CustomFormat ="yyyy-MM-dd"
timer倒计时关机
或Process.Start("shutdown","-s -t 时间秒");

111,098

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧