One, TimeSpan constants, fields
TimeSpan.MaxValue; 10675199.02:48:05.4775807
Timespan.minvalue; -10675199.02:48:05.4775808
TimeSpan.Zero; 0.00:00:00.0
Timespan.ticksperday; Number of ticks per day: 864000000000
Timespan.ticksperhour; Number of ticks in one hour: 36000000000
Timespan.tickspermillisecond; Number of ticks in a millisecond: 10000
Timespan.ticksperminute; Number of ticks in one minute: 600000000
Timespan.tickspersecond; Number of ticks in one second: 10000000
Second, TimeSpan static method
Timespan.compare (); Contrast
Timespan.equals (); //=
Timespan.fromdays (); Build from Days
Timespan.fromhours (); Set up from a small number of hours
Timespan.frommilliseconds (); Set from the number of milliseconds
Timespan.fromminutes (); From the number of minutes established
Timespan.fromseconds (); From the number of seconds to establish
Timespan.fromticks (); Build from Tick Count
Timespan.parse (); Build from String
Timespan.parseexact (); Creates a string from the specified format
Timespan.tryparse (); Try to build from a string
Timespan.tryparseexact (); Attempts to create a string from a specified format
Third, TimeSpan property
Days; Day part Hours; Hours section
Milliseconds; Millisecond section
Minutes; Sub-section
Seconds; Seconds part
Ticks; Total Ticks
Totaldays; Total Days
TotalHours; Total number of hours
TotalMilliseconds; Total number of milliseconds
Totalminutes; Total number of minutes
TotalSeconds; Total number of seconds
Iv. Method of TimeSpan
ADD (); + CompareTo (); Comparison of
Duration (); Absolute
Equals (); //
Negate (); Reverse, + >-、-> +
Subtract (); -, anti-manipulation of ADD ()
ToString (); Formatted to a string with. Net 4.0 changes compared to previous versions
V. TimeSpan building Objects
protected void Button1_Click (object sender, EventArgs e)
... {
TimeSpan T1 = new TimeSpan (864000000000); 1.00:00:00
TimeSpan t2 = new TimeSpan (23, 59, 59); 23:59:59
TimeSpan t3 = new TimeSpan (30, 23, 59, 59); 30.23:59:59
TimeSpan T4 = new TimeSpan (30, 23, 59, 59, 999); 30.23:59:59.9990000
Double F = 365.25;
TimeSpan T5 = timespan.fromdays (f); 365.06:00:00
TimeSpan T6 = timespan.fromhours (f * 24); 365.06:00:00
TimeSpan t7 = Timespan.fromminutes (f * 24 * 60); 365.06:00:00
TimeSpan T8 = Timespan.fromseconds (f * 24 * 60 * 60); 365.06:00:00
TimeSpan T9 = Timespan.frommilliseconds (f * 24 * 60 * 60 * 1000); 365.06:00:00
TimeSpan t0 = timespan.fromticks ((long) (f * 24 * 60 * 60 * 1000 * 10000)); 365.06:00:00
TextBox1.Text = string. Format ("{0}\n{1}\n{2}\n{3}\n{4}\n{5}\n{6}\n{7}\n{8}\n{9}",
T1, T2, T3, T4, T5, T6, T7, T8, T9, t0
);
}
function to find out the last published time
public string Da (www.111cn.net) testringfromnow (DateTime DT)
{
TimeSpan span = Datetime.now-dt;
if (span. Totaldays > 60)
{
Return dt. ToShortDateString ();
}
else if (span. Totaldays > 30)
{
return "1 months ago";
}
else if (span. Totaldays > 14)
{
Return "2 weeks ago";
}
else if (span. Totaldays > 7)
{
Return "1 weeks ago";
}
else if (span. Totaldays > 1)
{
return string. Format ("{0} days ago", (int) Math.floor (span. Totaldays));
}
else if (span. TotalHours > 1)
{
return string. Format ("{0} hours ago", (int) Math.floor (span). TotalHours));
}
else if (span. Totalminutes > 1)
{
return string. Format ("{0} minutes ago", (int) Math.floor (span). totalminutes));
}
else if (span. TotalSeconds >= 1)
{
return string. Format ("{0} seconds ago", (int) Math.floor (span). TotalSeconds));
}
Else
{
Return "1 seconds ago";
}
}
Common members in DateTime and TimeSpan and their descriptions
The
Property describes
Date gets the part of this instance.
Day Gets the date represented by this instance as the day ordinal of the month.
DayOfWeek Gets the day of the week that this instance represents.
DayOfYear Gets the date represented by this instance is the day ordinal of the year. The
Hour gets the hour portion of the date represented by this instance. The
millisecond gets the millisecond portion of the date represented by this instance. The
Minute gets the minute portion of the date represented by this instance.
Month gets the month portion of the date represented by this instance.
Now creates a DateTime instance, which is the current local date and time on this computer. The
Second gets the seconds portion of the date represented by this instance.
TimeOfDay Gets the time of day for this instance.
Today gets the current date.
year gets the years portion of the date represented by this instance.
Common Properties and descriptions of the 01:datetime class for the table
Method description
Add adds the value of the specified timespan to the value of this instance.
AddDays adds the specified number of days to the value of this instance.
AddHours adds the specified number of hours to the value of this instance.
Addmilliseconds adds the specified number of milliseconds to the value of this instance.
AddMinutes adds the specified number of minutes to the value of this instance.
AddMonths adds the specified number of months to the value of this instance.
AddSeconds adds the specified number of seconds to the value of this instance.
AddYears adds the specified number of years to the value of this instance.
DaysInMonth returns the number of days in the specified month in the specified year.
Isleapyear returns whether the specified year is an indication of leap years.
Parse converts the specified string representation of a date and time to its equivalent datetime instance.
Subtract subtracts the specified time or duration from this instance.
Tolongdatestring converts the value of this instance to its equivalent long date string representation.
Tolongtimestring converts the value of this instance to its equivalent long-time string representation.
Toshorttimestring converts the value of this instance to its equivalent short-time string representation.
ToShortDateString converts the value of this instance to its equivalent short date string representation.
The common method of table 02:datetime structure and its explanation
Table 03 and Table 04 are the common properties and common methods of the timespan structure and their descriptions:
Property Description
Day gets the number of days represented by this instance.
Hours gets the number of full hours represented by this instance.
Milliseconds gets the number of full milliseconds represented by this instance.
Minutes gets the number of full minutes represented by this instance.
Seconds gets the number of full seconds represented by this instance.
Ticks gets the value of this instance represented by a scale.
Totaldays gets the value of this instance expressed as a decimal part of the day and the day.
TotalHours gets the value of this instance expressed as a decimal part of the whole hour and hour.
TotalMilliseconds gets the value of this instance, expressed in the integer milliseconds and the number of milliseconds.
Totalminutes Gets the value of this instance expressed as a decimal part of the whole minute and minutes.
TotalSeconds Gets the value of this instance, expressed in the integer seconds and the number of seconds.
Common Properties of Table 03:timespan structure and its description
Method description
Add adds the specified timespan to this instance.
Duration returns a timespan whose value is absolute for this instance.
Fromdays returns a TimeSpan that represents the specified number of days, where the specified number of days is accurate to the nearest millisecond.
Fromhours returns a TimeSpan that represents the specified number of hours, where the specified number of hours is accurate to the nearest millisecond.
Frommilliseconds returns a TimeSpan that represents the specified number of milliseconds.
The Fromminutes returns a timespan that represents the specified number of minutes, where the specified number of minutes is accurate to the nearest millisecond.
FromSeconds returns a TimeSpan that represents the specified number of seconds, where the specified number of seconds is exactly the nearest millisecond.
Subtract subtracts the specified timespan from this instance.
The common methods of table 04:timespan structure and its explanation from:http://www.111cn.net/net/net/58093.htm
Asp. Use of TimeSpan in net