JS and C # for time stamp conversion _javascript skills

Source: Internet
Author: User

JS time stamp into C # time, and then the C # time stamp into JS time

The time stamp in JS

Copy Code code as follows:

var dt = new Date (). GetTime ();//Time stamp

C # time stamp turn time

Copy Code code as follows:

DateTime Dtstart = TimeZone.CurrentTimeZone.ToLocalTime (New DateTime (1970, 1, 1));
Long ltime = long.  Parse (dt + "0000"); Description, the time format is 13 digits after 4 "0", if the time format of 10 digits then add 7 "0", as for why I am not too clear, but also in the same way that people write code conversion
TimeSpan Tonow = new TimeSpan (ltime);
DateTime Dtresult = Dtstart.add (Tonow); Get the time after conversion

-------------------------------------------------------------------------------
C # time-turn timestamp

Copy Code code as follows:

System. DateTime starttime = TimeZone.CurrentTimeZone.ToLocalTime (new System. DateTime (1970, 1, 1, 0, 0, 0, 0));
Intresult = (time-starttime). TotalMilliseconds;
DateTime dtresult//Fetch Time
Long T = (dtresult.ticks-starttime.ticks)/10000;//except 10000 adjusts to 13 bits

Js

Copy Code code as follows:

var d = new Date (data); Time Stamp Turn time
Alert (FormatDate (d));
Format time
function FormatDate (now) {
var year=now.getfullyear ();
var month=now.getmonth () +1;
var date=now.getdate ();
var hour=now.gethours ();
var minute=now.getminutes ();
var second=now.getseconds ();
return year+ "-" +month+ "-" +date+ "" +hour+ ":" +minute+ ":" +second; "
}

The code is super simple, but it is very practical, small partners to refer to the

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.