JS and PHP timestamp and date conversion

Source: Internet
Author: User
JS Timestamp Turn Date:

function Getymdhms (time) {var date = new Date (parseint (time) * 1000);//Get a Temporal object  Note: If the timestamp is Uinx, remember to multiply by 1000. For example, the PHP function time () to get the timestamp will be multiplied by 1000//console.log (Date.getfullyear ());/*----------Below is the method to get the time date, What format do you need to stitch up yourself----------*///date.getfullyear ();//Get the full year (4-bit, 1970)//date.getmonth ();//Get month (0-11, 0 for January, When using, remember to add 1)//date.getdate ();//Get the Day (1-31)//date.gettime ();//Get Time (number of milliseconds starting in 1970.1.1)//date.gethours ();//Get Hours (0-23)/ /date.getminutes ();//Gets the number of minutes (0-59)//date.getseconds ();//Gets the number of seconds (0-59) 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 1000Y = date.getfullyear () + '-'; M = (Date.getmonth () +1 < 10? ' 0 ' + (date.getmonth () +1): Date.getmonth () +1) + '-';D = date.getdate () + '; h = (Date.gethours () < 10? ' 0 ' +date.gethours (): Date.gethours ()) + ': '; m = (Date.getminutes () < 10?) ' 0 ' +date.getminutes (): Date.getminutes ()) + ': '; s = (Date.getseconds () < 10? ' 0 ' +date.getseconds (): Date.getseconds ()); return y+m+d+h+m+s;}

JS Date turn timestamp:

Start_date=new Date (current_year+ '-' +current_month+ '-01 00:00:00 ');
End_date=new Date (current_year+ '-' + (parseint (current_month) +1) + '-01 00:00:00 ');

st = Date.parse (start_date)/1000; The time stamp obtained in addition to 1000 can be used to obtain the UNIX timestamp, when the value is passed to PHP.
ET = Date.parse (end_date)/1000;


PHP Date turn timestamp:


$time = $_post["Time"];
$time = Strtotime ($time) -8*3600;

PHP Timestamp Transfer Date:

Date_default_timezone_set (' PRC '); China time Zone
$time =date (' y-m-d h:i:s ', $result [' time ']);

The above describes the JS and PHP timestamp and date conversion, including the aspects of the content, I hope the PHP tutorial interested in a friend helpful.

  • Related Article

    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.