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; }   
Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.