Conversion between JS timestamp and date format

Source: Internet
Author: User

Conversion method:

var date = new Date (timestamp);

Get a Time object note: If the timestamp is Uinx, remember to multiply at 1000.

For example, PHP function time () to get the timestamp will be multiplied by 1000

//获取时间日期的方法date.getFullYear();//获取完整的年份(4位,1970)date.getMonth();//获取月份(0-11,0代表1月,用的时候记得加上1)date.getDate();//获取日(1-31)date.getTime();//获取时间(从1970.1.1开始的毫秒数)date.getHours();//获取小时数(0-23)date.getMinutes();//获取分钟数(0-59)date.getSeconds();//获取秒数(0-59)

Format method: Yyyy-mm-dd hh:mm:ss


//输出结果:2014-04-23 18:55:49
Convert date format to timestamp

Pass in a time format, if not passed is to get the current time, it is so simple.

There are three ways of getting

time1 = Date.gettime () time2 = date.valueof () Time3 = Date.parse (date)

Three types of acquisition the first, the second: it will be accurate to the millisecond third: only accurate to the second, milliseconds will be replaced by the number of

The result of the above code output

1398250549123

1398250549123

1398250549000

Note: Note: The time stamp obtained in addition to 1000 can get Unix timestamp, when the value of the PHP is used to get

Conversion between JS timestamp and date format

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.