Declare a TimeSpan
System.TimeSpan ts = dtnightend.subtract (Dtamstart);
//
Dtnightend is the original time minus Dtamstart this time
Get a TimeSpan
TimeSpan with the interval attribute
Rsh Days.tostring (); Rsh Hours.tostring ();
Rsh Minutes.tostring (); Rsh Seconds.tostring ();
Wait, these are separate days, minutes, seconds.
//
And the total spacing is expressed in hours and minutes.
Rsh Totalminutes.tostring (); Wait a minute
Comparison of the 1st period
datetime t1 = new DateTime (2002,5,30);
DateTime t2 = new DateTime (2002,5,23);
TimeSpan diff=t1-t2;
MessageBox.Show (diff. Days.tostring ());
//
2 system date
System.DateTime.Now.ToString ()
//
3 Character Turn time
DateTime d1=convert.todatetime ("2003-01-01 18:20:01");
String s=d1. ToString ("Yyyy-mm-dd HH:mm:ss");
MessageBox.Show (s);
Dictionary set System.Collections.SortedList mengdiwc=new System.Collections.SortedList ();
DateTime dt1=convert.todatetime ("2008-01-01 10:11:12");
DateTime dt2=convert.todatetime ("2008-01-02 10:13:13");
System.TimeSpan ts = dt2-dt1;
Textbox1.text=ts. Days.tostring () + "Days" +ts. Hours.tostring () + "when" +ts. Minutes.tostring () + "min" +ts. Seconds.tostring () + "SEC >>" +ts. Totalminutes.tostring ();
Sometimes we have to change the time to achieve different display effects.
The default format is: 2005-6-6 14:33:34
What if you want to change into a 200506,06-2005,2005-6-6 or more?
We need to use: DateTime.ToString method (String, IFormatProvider)
Using System;
Using System.Globalization;
String format= "D";
DateTime Date=datatime,now;
Response.Write (date. ToString (format, datetimeformatinfo.invariantinfo));
Result output
Thursday, June 16, 2005
Parameter format format verbose usage
Format Character Association attribute/description
D ShortDatePattern-----08/30/2006
D Longdatepattern-----Wednesday, August 2006
F Full Date and time (long date and short time)-----Wednesday, August 2006 23:21
F Fulldatetimepattern (long date and long time)-----Wednesday August 2006 23:22:02
G General (short date and short time)-----08/30/2006 23:22
G General (short date and long time)-----08/30/2006 23:23:11
M, M Monthdaypattern
R, R Rfc1123pattern
s use local time Sortabledatetimepattern (based on ISO 8601)
T shorttimepattern------23:24
T longtimepattern-------23:24:30
U universalsortabledatetimepattern format for displaying Universal Time-------2006-08-30 23:25:10z
U use the full date and time of the universal Time (long date and long time)-----Wednesday,