| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 2105 人关注过本帖
标题:简单的错误及DateAndTime.DateDiff问题
取消只看楼主 加入收藏
花间酒
Rank: 2
等 级:论坛游民
帖 子:13
专家分:24
注 册:2017-4-4
结帖率:100%
收藏
 问题点数:0 回复次数:1 
简单的错误及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百度过,语法没错,但不知为什么就出错了,还望大神指教,谢谢了
搜索更多相关主题的帖子: System Text DateTime ToString Convert 
2017-09-12 23:54
花间酒
Rank: 2
等 级:论坛游民
帖 子:13
专家分:24
注 册:2017-4-4
收藏
得分:0 
少了引用集
2017-09-14 11:03
快速回复:简单的错误及DateAndTime.DateDiff问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.013716 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved