C # Timestamp conversion (RPM)

Source: Internet
Author: User

In. NET-based applications, UNIX timestamps are not used and UNIX timestamps are used when the. NET app interacts with other applications (eg:php, Java). Once used in the project, users submit data through the Web app and share to the Android app, if the time interval within a minute, the data can be true and effective, otherwise not processed. in ASP. NET development, it is often necessary to serialize the object into JSON data, JS stitching into HTML, the Date object will be serialized into the following form: {"date": "\/date (1349839763373) \"},js is not recognized, Consider converting the date to a Unix timestamp.

The following is the conversion of dates and Unix timestamps under C #:

<summary>///Date converted to UNIX timestamp///</summary>///<param name= "DateTime" ></param>///< Returns></returns>public Static Long Datetimetounixtimestamp (datetime datetime) {    var start = new DateTime (1970, 1, 1, 0, 0, 0, datetime.kind);    Return Convert.toint64 ((Datetime-start). totalseconds);} <summary>///Unix timestamp converted to date//</summary>///<param name= "Unixtimestamp" > Timestamp (seconds) </param>// /<returns></returns>public static datetime unixtimestamptodatetime (this datetime target, long timestamp) {    var start = new DateTime (1970, 1, 1, 0, 0, 0, Target. Kind);    return start. AddSeconds (timestamp);}

Next to this date (1970-1-1), the computer and some electronic equipment time calculation and display is based on the calendar element (that is, Greenwich Mean Time January 1, 1970 00:00:00.000, Gregorian calendar) offset of the standard, some people jokingly called the British Green Wedge Observatory is " The place where time began. "

C # Timestamp conversion (RPM)

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.