JS microtime vs php microtime

I am using the ganttchart plugin. I download the plugin using json: Plugin: GitHub - JQuery Gantt

{ "name": "Zbigniew Kowalski", "desc": "Administrator", "values": [ {"from": "/Date(1310508000000)/", "to": "/Date(1311026400000)/", "desc": "<b>Type</b>: Task<br/><b>name</b>: Task 5<br/><b>Description</b>: Task desc."} ] }, 

So, if I try to generate such a block, I get some decent problems with micro-time.

microtime in php gives me: 0.77424900 1315815507 and time: 1315815507

but I need something like 1310508000000.

can't it be the key only to add 0?

+4
source share
3 answers

yu should use microtime(true) to set the float value and then multiply it by 1000 to get microseconds:

 $time = microtime(true)*1000; 

See the documentation for more information.

+3
source

This is the way to create a JavaScript date object from a PHP timestamp:

 new Date('<?php echo date('r'); ?>'); 
0
source

in you js you can do:

 var timer = 1315815507; var float = Math.round(parseInt(timer)/1000000)*1000000; 

this will give you: 1316000000

live example: http://jsfiddle.net/DBjS8/1/

0
source

All Articles