Reputation: 2586
how can i convert datetime from JS return by this function
var now = new Date();
output: Sun Feb 24 2013 01:26:47 GMT+0800 (MYT)
into php readable format such as date(YmdHis)
?
Upvotes: 1
Views: 193
Reputation: 2418
Return a UNIX timestamp from your Javascript function:
Math.round(new Date().getTime() / 1000) //returns number of seconds since epoch
Then simply use that in PHPs date function:
$yourJsTime = $_GET['jsTime']; //depends on how you pass your js timestamp
date_default_timezone_set('UTC');
echo date('YmdHis', $yourJsTime);
Upvotes: 1