如何使用asp.net比较两种日期格式 [英] How to compare two dates formats using asp.net

查看:88
本文介绍了如何使用asp.net比较两种日期格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨...

如何使用c#.net比较两种日期格式(MM / dd / yyyy)。

Ex:

Hi...
How to compare two dates formats(MM/dd/yyyy) using c#.net?.
Ex:

string dt="16/01/2014";
string dt0="12/31/2013";
if(dt != dt0)
{
} 



像这样,怎么样?

请帮助我。谢谢你。


like this,how?
Pls help me. Thank u.

推荐答案

试试这样..



Try like this..

string dt = "16/01/2014";
       string dt0 = "12/31/2013";
       DateTime dt_date0 = DateTime.ParseExact(dt, "dd/MM/yyyy", null);
       DateTime dt_date1 = DateTime.ParseExact(dt0, "dd/MM/yyyy", null);
       if (dt_date0 != dt_date1)
       {



}



参考 DateTime.ParseExact [ ^ ]


DateTime dt = new DateTime();
 dt = DateTime.ParseExact("your date here", "MM/dd/yyyy", null);  //converting string into standard datetime format







使用上面的代码转换两个日期然后比较




convert both dates using above code and then compare


试试这个..





Try this..


DateTime datet ,date0;
             string dt = "16/01/2014"; //  dd/MM/yyyy.
             string dt0 = "12/31/2013"; // MM/dd/yyyy

            string[] splitdate=new string[3];
            splitdate = dt.Split('/');


            dt = splitdate[1].ToString() + "/" + splitdate[0].ToString() + "/"  +splitdate[2].ToString();
            datet = Convert.ToDateTime(dt);
            date0 = Convert.ToDateTime(dt0);
            if (datet != date0)
            { 
            }


这篇关于如何使用asp.net比较两种日期格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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