Js obtains the unix timestamp

Source: Internet
Author: User

Js does not have a function similar to php's time () function class to directly obtain unix timestamp timestamps. Therefore, it is inconvenient for some numbers that need to be generated at random time, the following is a function that is similar to getting unix timestamps in php.

Var time = Math. round (new Date (). getTime ()/1000 );

Explain the code below:

New Date () initializes a Date and time object

Get. Time () is divided by 1000 because it takes milliseconds.

Math. round rounds the value to the nearest integer or the specified number of decimal places, which is similar to php's ceil function.

Articles you may be interested in
  • Mysql converts unix timestamp to date format, and MySQL queries the current time
  • Conversion of date and unix timestamps in php and mysql
  • How to verify the validity of date and time using javascript
  • When CuteFTP is connected to the ftp server, the "invalid Parameters" error is displayed.
  • How to obtain information about the Year, Zodiac, and constellation of the rule by using the date or timestamp in php
  • Analysis of js setInterval and setTimeout usage
  • How to set the jump wait time for the thinkphp page Jump (successerror)
  • Php obtains the start time and end time timestamp of the week of the specified date.

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.