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