Asp. Use of TimeSpan in net

Source: Internet
Author: User

In ASP. NET, subtract two times, get a TimeSpan instance, TimeSpan has some properties: Days, Totaldays, Hours, TotalHours, Minutes, Totalminutes, Seconds, TotalSeconds, Ticks, note that there is no totalticks.

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;//Tick of the day: 864000000000
TimeSpan. Ticksperhour;Tick count per hour: 36000000000
TimeSpan. Tickspermillisecond;number of ticks per millisecond: 10000
TimeSpan. Ticksperminute;Tick count for one minute: 600000000
TimeSpan. Tickspersecond;Tick count for 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 ();//From the number of milliseconds established
TimeSpan. Fromminutes ();//From the number of minutes established
TimeSpan. FromSeconds ();//From the number of seconds established
TimeSpan. Fromticks ();//Build from Tick count
TimeSpan. Parse ();//From string creation
TimeSpan. ParseExact ();//Create a string from the specified format
TimeSpan. TryParse ();//Try to build from a string
TimeSpan. TryParseExact ();//Try to create a string from the specified format

Third, TimeSpan Property

Days;//Day partHours;//hour part
Milliseconds;//Millisecond Section
Minutes;//Sub-section
Seconds;//Sec Part
Ticks;Total//tick
Totaldays;//Total days
TotalHours;//Total number of hours
TotalMilliseconds;//Total number of milliseconds
Totalminutes;//Total number of minutes
TotalSeconds;//Total number of seconds


Four, TimeSpan Method

ADD (); // + CompareTo (); //Compare to
Duration (); //Absolute value
Equals (); //
Negate (); //reverse, + >-、-> +
Subtract (); //-, anti-manipulation of ADD ()
ToString (); //formatted to string,. Net 4.0 changes compared to previous versions

V.TimeSpan building Objects

 C # code replication
Protected voidButton1_Click (Objectsender, EventArgs e){TimeSpan T1= NewTimeSpan (864000000000);//1.00:00:00TimeSpan T2= NewTimeSpan (23,59,59);//23:59:59TimeSpan T3= NewTimeSpan (30,23,59,59);//30.23:59:59TimeSpan T4= NewTimeSpan (30,23,59,59,999);//30.23:59:59.9990000 DoubleF= 365.25; TimeSpan T5=Timespan.fromdays (f);//365.06:00:00TimeSpan T6=Timespan.fromhours (f* 24);//365.06:00:00TimeSpan T7=Timespan.fromminutes (f* 24 * 60);//365.06:00:00TimeSpan T8=Timespan.fromseconds (f* 24 * 60 * 60);//365.06:00:00TimeSpan T9=Timespan.frommilliseconds (f*    *   [  *   +   *   + ]; // 365.06:00:00   TimeSpan t0  =  timespan.fromticks (( long ) (F  *     *   $   *   $   *   +   *   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);}                  /span>                 

Vi. instances of TimeSpan

C # codeCopy
Time1Is2010-1-2 8:43:35; time2Is2010-1-12 8:43:34。 Use time2Time reduction1, you get a TimeSpan instance. So time2than time1Many9Days23Hours59Score of59Seconds. So, Days is9, Hours is23, Minutes is59, Seconds is59。 Look againTicks, Tick is a chronograph that represents 100 nanoseconds, or one out of 10,000 seconds, so Ticks here indicates how many time periods are different in total, namely:9 * 24 * 3600 * 10000000 + 23 * 3600 * 10000000 + 59 * 60 * 10000000 + 59 * 10000000 = 8639990000000。3600Is the number of seconds in an hour.totaldaysis to convert Ticks to Rewardcash octopus number, i.e.:8639990000000 /(10000000  *   [  *   3600 ]  =   9.99998842592593 .  TotalHours  translates Ticks into hours, that is:  8639990000000  / ( 10000000   *   3600 )  =   239.999722222222 .  Totalminutes  is the conversion of Ticks into minutes, that is:  8639990000000  / ( 10000000   *   )  =   14399.9833333333 .  TotalSeconds  is the conversion of Ticks into seconds, i.e.  8639990000000  / ( 10000000 )  =   863999 .    

ASP. NET in the use of TimeSpan

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.