C # Compare time size 1, compare time size experiment

Source: Internet
Author: User

1. Comparison of time and size experiments
  stringst1="12:13"; stringSt2="14:14"; DateTime DT1=Convert.todatetime (ST1); DateTime DT2=Convert.todatetime (ST2); DateTime DT3=DateTime.Now; if(Datetime.compare (DT1,DT2) >0) Msg. Text=st1+">"+St2; ElseMsg. Text=st1+"<"+St2; Msg. Text+="\ r \ n"+DT1.     ToString (); if(Datetime.compare (DT1,DT3) >0) Msg. Text+="\ r \ n"+st1+">"+DT3.     ToString (); ElseMsg. Text+="\ r \ n"+st1+"<"+dt3. ToString ();

2. Calculates the function of two time difference value, returns the absolute value of the time difference:
 Private stringDateDiff (DateTime datetime1,datetime DateTime2) {stringdatediff=NULL; Try{TimeSpan Ts1=NewTimeSpan (datetime1.ticks); TimeSpan ts2=NewTimeSpan (datetime2.ticks); TimeSpan TS=Ts1. Subtract (TS2).                  Duration (); DateDiff=ts. Days.tostring () +"days"+ts. Hours.tostring () +"hours"+ts. Minutes.tostring () +"minutes"+ts. Seconds.tostring () +"seconds"; }              Catch              {              }              returnDateDiff; }

3. Realize the function of calculating datetime1-36 day =datetime2
TimeSpan ts=New TimeSpan (0,0,0);     DateTime DT2=DateTime.Now.Subtract (ts);     Msg. Text=datetime.now.tostring () +"-"+ts. Days.tostring () +" days \ r \ n";     Msg. Text

C # Compare time size 1, compare time size experiment

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.