Convert date problem

Hi, how can I convert this utc date and time to my local timezone (UTC + 08:00) ?

150423160509 
to
2015-04-24 00:05:09  

I already succeed this using php, but I want to convert this using javascript.

This is how I convert this to php

function mylocaltimezone($utctime){

    $utc = DateTime::createFromFormat('ymdHis', $utctime);
    $utclocal= $utc->format('Y-m-d H:i:s');
    $local = new DateTime($utclocal);
    $local->add(new DateInterval('PT8H'));
    $theloctime = $local->format('Y-m-d H:i:s');

    return $theloctime;
}

Thank you in advance.

JavaScript only has very basic methods available on the Date() object. It is possible to create an extended version of the date object that adds the more advanced functionality. For example http://javascriptexample.net/dollarD.php

That extended date object includes a format() method so that your code

could (assuming you created $utc as an object based on that extended date one) be written in JavaScript as

$utc.format('Y-m-d H:i:s');

I have not looked into the possibility of adding equivalents to those other PHP date processes but presumably they would also be possible.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.