C # Datetime.ticks converts time into seconds and GMT

Source: Internet
Author: User

Reproduced in: http://blog.csdn.net/tyxkzzf/article/details/49132237

Before programming, know how big Timespan.ticks is in C #:
Tick the smallest time unit scale, equivalent to 100 nanometers (1 nai seconds equals one-zero seconds). The scale can be positive and negative.
Here's a C # example to calculate the time difference for the next two dates.
DateTime dt = new DateTime (1970, 1, 1);
TimeSpan d =datetime.parse ("2011/12/24 9:41:40")-DT;
Long Seconddiff =d.ticks/10000000;
The calculated D.ticks is in nanoseconds and must be divided into seconds to divide by 1000000000; the result is 1324719700;
That, in turn, is known to date, the date of the N-second difference between this date, is the number of seconds of the date has been calculated, and then the difference between the number of seconds to add.
What is the date of January 1, 1970 with a difference of 1324719700 seconds?
DateTime dt = new DateTime (1970, 1, 1);
DateTime Ts=dt. AddSeconds (1324719700);
MessageBox.Show (TS. ToString ("Yyyy/mm/dd hh:mm:ss"));
Get results for 2011/12/24 9:41:40

C # Datetime.ticks converts time into seconds and GMT

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.