本文介绍了只比较上午的时间,例如上午10:15的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有两个时间,我想比较这两个时间,也想知道AM还是PM哪个更大或更小.

如果我有
上午10:15和下午2:00

我使用datetime并将其转换为以hh:mm tt
表示的字符串
我用像

Hello,

I have two time and i want to compare these two time and want to know which one is greater or smaller with AM or PM also.

if i have
10:15 AM and 2:00 PM

i use datetime and i convert that into string for taking as hh:mm tt

i use like

protected void Button1_Click(object sender, EventArgs e)
    {
        string s = "";
        s = drop_leave_hh.SelectedItem.Value + ":" + drop_leave_mm.SelectedItem.Value+""+drop_leave_time_dest.SelectedItem.Value;
       
        DateTime dt = System.Convert.ToDateTime(s);
        string leave_time = dt.ToString("hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);
        string nw = DateTime.Now.ToString("hh:mm tt", System.Globalization.DateTimeFormatInfo.InvariantInfo);
    }



所以,我想比较这两个时间.我该如何实现呢?

在此先感谢...
Mitesh



so, i want to compare these two time.how can i achieve this.

Thanks in Advance...
Mitesh

推荐答案

private void Form1_Load(object sender, EventArgs e)
{
         string strtime1 = "10:15 AM";
         DateTime time1 = Convert.ToDateTime(strtime1);
         string strtime2 = "2:00 PM";
         DateTime time2 = Convert.ToDateTime(strtime2);

         if (time1.TimeOfDay > time2.TimeOfDay)
            MessageBox.Show("Time1 is later than Time2");
         else
            MessageBox.Show("Time2 is later than Time1");
}


这篇关于只比较上午的时间,例如上午10:15的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:03