简单的错误及DateAndTime.DateDiff问题
using System;using System.Collections.Generic;
using
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace ClockAlarm
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string strHour = DateTime.Now.TimeOfDay.Hours.ToString();
string strMouit = DateTime.Now.TimeOfDay.Minutes.ToString();
string strSecon = DateTime.Now.TimeOfDay.Seconds.ToString();
if (Convert.ToInt32(strHour) < 10)
{
strHour = "0" + strHour;
}
if (Convert.ToInt32(strMouit) <10)
{
strMouit = "0" + strMouit;
}
if (Convert.ToInt32(strSecon) < 10)
{
strSecon = "0" + strSecon;
}
textBox2.Text = strHour + ";" + strMouit + ":" + strSecon;
int Hour = Convert.ToInt32(strHour);
int Mouit = Convert.ToInt32(strMouit);
int Secon = Convert.ToInt32(strSecon );
numericUpDown3.Value = Convert.ToInt32(strHour );
numericUpDown2.Value = Convert.ToInt32(strSecon );
numericUpDown1.Value = Convert.ToInt32(strSecon );
}
private void timer1_Tick(object sender, EventArgs e)
{
string strHour = DateTime.Now.TimeOfDay.Hours.ToString();
string strMouit = DateTime.Now.TimeOfDay.Minutes.ToString();
string strSecon = DateTime.Now.TimeOfDay.Seconds.ToString();
if (Convert.ToInt32(strHour) < 10)
{
strHour = "0" + strHour;
}
if (Convert.ToInt32(strMouit) < 10)
{
strMouit = "0" + strMouit;
}
if (Convert.ToInt32(strSecon) < 10)
{
strSecon = "0" + strSecon;
}
textBox1.Text = strHour + ":" + strMouit + ":" + strSecon;
}
private void button1_Click(object sender, EventArgs e)
{
DateTime get_time1 = Convert.ToDateTime(DateTime.Now.ToString());
DateTime sta_ontime1 = Convert.ToDateTime(Convert.ToDateTime(textBox2.Text.Trim().ToString()));
long dat = DateAndTime.DateDiff("s",get_time1 ,sta_ontime1 ,FirstDayOfWeek.Sunday,FirstWeekOfYear.FirstFourDays);//此处我有错误
if (dat > 0)
{
timer2.Enabled = true;
label4.Text = "闹钟已启动";
label1.Text = "剩余" + dat.ToString() + "秒";
}
else
{
MessageBox.Show("闹钟已启动,请取消后,再启动");
}
else//此处???
{
long hour =24*3600+dat;
timer2 .Enabled =true;
label4 .Text ="闹钟已启动";
label1 .Text ="剩余"+hour .ToString ()+"秒";
}
}
private void timer2_Tick(object sender, EventArgs e)
{
DateTime get_time1 = Convert.ToDateTime(DateTime .Now .ToString ());
DateTime sta_ontime1 = Convert.ToDateTime(Convert .ToDateTime (textBox2 .Text .Trim ().ToString ()));
long dat = DateAndTime.DateDiff("s", get_time1, sta_ontime1, FirstDayOfWeek.Sunday, FirstWeekOfYear.FirstFourDays);//此处我有错误
if (dat == 0)
{
label4.Text = "时间已到";
timer2.Enabled = false;
}
else
{
label1.Text = "剩余" + dat.ToString() + "秒";
}
}
}
}
代码如上,DateAndTime.DateDiff百度过,语法没错,但不知为什么就出错了,还望大神指教,谢谢了