JS SQL C # time, timestamps convert each other

Source: Internet
Author: User

JS, SQL, C # time, timestamps convert each other

//1 . Gets the current timestamp _c# Long 621355968000000000 10000000
 // 2. Time stamp, C #  DateTime B11 = GetTime ( "); //  11-bit timestamp, time  DateTime B13 = convertstringtodatetime (  1483461862  ); //  13-bit timestamp, time  
// 3. Time-stamped C #int a11= convertdatetimeint (B11); // Timestamp, 11-bit time long A13 = Convertdatetimetoint (B13); // Timestamp, 13-bit time

 PrivateDateTime GetTime (stringTimeStamp)//11 Timestamp converted to C # format time{DateTime Dtstart= TimeZone.CurrentTimeZone.ToLocalTime (NewDateTime (1970,1,1)); LongLtime =Long. Parse (TimeStamp +"0000000"); TimeSpan Tonow=NewTimeSpan (Ltime);returnDtstart.add (Tonow); }        Private intConvertdatetimeint (System.DateTime time)//Convert one-time datetime format to UNIX timestamp format{System.DateTime StartTime= TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1)); return(int) (Time-startTime).        TotalSeconds; }                 Public Static LongConvertdatetimetoint (System.DateTime time)////13-bit time converted to time{System.DateTime StartTime= TimeZone.CurrentTimeZone.ToLocalTime (NewSystem.DateTime (1970,1,1,0,0,0,0)); LongT = (time. Ticks-starttime.ticks)/10000;//except 10000 adjustment for 13 bit            returnT; }                    PrivateDateTime Convertstringtodatetime (stringTimeStamp)//13-bit timestamp converted to C # format time{DateTime Dtstart= TimeZone.CurrentTimeZone.ToLocalTime (NewDateTime (1970,1,1)); LongLtime =Long. Parse (TimeStamp +"0000"); TimeSpan Tonow=NewTimeSpan (ltime); returnDtstart.add (Tonow); } 

Sql

-- 1 current timestamp get SQL    SELECT DATEDIFF (S,'1970-01-01 00:00:00'GETDATE-8*  3600    SELECTDATEDIFF'1970-01-01 00:00:00', getUTCDate ())
 -- 2 timestamp → normal time sql  select  dateadd  (S, 1483461862 ,  1970-01-01 08:00:00    ") as   select  dateadd  (S,1483461862  +  8  *  3600 , Span style= "color: #ff0000;" > '  
-- 3 Normal time →unix timestamp SQL     SELECT DATEDIFF ' 1970-01-01 08:00:00 ' ' 2017-01-04 00:44:22.000 ')

Js

1 Current timestamp gets jsmath.round (new Date (). GetTime ()/1000)
2 time stamp → normal time js   var New Date (Unix timestamp *var commontime =unixtimestamp.tolocalestring ();
3 normal time →unix timestamp jsvarnew Date (DATE.UTC (year, month-1, day, hour, minute, second))

JS SQL C # time, timestamps convert each other

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.