日期比较大小

   using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConTest
{
    class Program
    {
        static void Main(string[] args)
        {
            DateTime dt1 = DateTime.Now.Date;
            DateTime dt2 = DateTime.Now.AddDays(1).Date;
            string dt3 = dt1.ToString("yyyy-MM-dd");//输出2013-4-22
            System.Windows.Forms.MessageBox.Show(dt3);
           // DateTime dt2 = DateTime.Now.AddDays(1).Date;           
            if (dt1>dt2)
            {
                global::System.Windows.Forms.MessageBox.Show("大于");
            }
            else if (dt1 < dt2)
            {
                global::System.Windows.Forms.MessageBox.Show("小于");
            }
            else
            {
                global::System.Windows.Forms.MessageBox.Show("相等");
            }

            if (dt1>dt2)
            {
                global::System.Windows.Forms.MessageBox.Show("大于");
            }
            else if (dt1 < dt2)
            {
                global::System.Windows.Forms.MessageBox.Show("小于");
            }
            else
            {
                global::System.Windows.Forms.MessageBox.Show("相等");
            }

            Console.Read();
        }
    }
}


 

posted @ 2013-04-24 18:27  Predator  阅读(136)  评论(0编辑  收藏  举报