JS time format and timestamp mutual conversion sample code

Source: Internet
Author: User
Tags getdate

  A lot of novice friends of JS in the time format and time stamp conversion is unfamiliar, below for you detailed introduction of the specific conversion steps, interested friends can refer to the following

A. Time conversion timestamp     code is as follows: function TransDate (endtime) {  var date=new date ();  date.setfullyear ( Endtime.substring (0,4));  Date.setmonth (endtime.substring (5,7)-1);  Date.setdate (endTime.substring ( 8,10));  date.sethours (endtime.substring (11,13));  date.setminutes (endtime.substring (14,16));  Date.setseconds (endtime.substring (17,19));  return Date.parse (Date)/1000; }    two. Timestamp conversion time   (1): Convert to 2011-3-16 16:50:43 format:  code is as follows: function GetDate (tm) {  var tt=new Date (parseint (tm) * 1000). Tolocalestrin g (). Replace (/year | month/g, "-"). Replace (/day/g, "")   return tt; }    (2): Convert to March 16, 2011 16:50:43:  code as follows : function GetDate (tm) {  var tt=new Date (parseint (tm) * 1000). toLocaleString ()   return tt; }    (3): Convert to March 16, 2011 16:50  code is as follows: function GetDate (tm) {  var tt=new Date (parseint (tm) * 1000). toLocaleString (). s Ubstr (0,16);  return tt; }   

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.