C # mutual conversion between the current time and number

Source: Internet
Author: User

1,January 1, 1900

Datetime oldtime = Convert. todatetime ( " 1900-1-1 00:00:00 " ); // Construct January 1, 1900
Timespan TS = Datetime. Now. Subtract (oldtime); // calculate the interval from January 1, January 1, 1900 to the present
Double Num = TS. totalseconds; // calculates the total number of seconds for this interval.
Response. Write (Num + " <Br/> " );
Datetime numtodate = Oldtime. addseconds (Num); // Add this number of seconds based on January 1, January 1, 1900 to restore to time
Response. Write (numtodate. tostring ());


2, 00January 1, year 00

 

Datetime time = new datetime (, 5); response. write ("ticks:" + time. ticks + "<br/>"); response. write ("time:" + new datetime (time. ticks ));

Datetime time = new datetime (2005, 5); // constructTime type of January 1, December 5

Response. Write ("ticks:" + time. ticks + "<br/>"); // time. ticks is00March January 1, year 002005Value of the long type in December 5, in the unit of 100 Hao-microseconds

Response. Write ("time:" + new datetime (time. ticks); // new datetime (time. ticks) is restored from a long value to a time type.

 

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.