开发者

JS microtime vs php microtime

i'm using a plugin for a ganttchart. i feed the plugin with json: Plugin: GitHub - JQuery Gantt

{ "name": "Zbigniew Kowalski",
   "desc": "Administrator",
   "values": [
       {"from": "/Date(1310508000000)/", "to": "/Date(13开发者_JS百科11026400000)/", "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 uhm i get some decent problems with the microtime.

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

but i need something like 1310508000000.

it can't be the key just to add some 0's ?


yu should use microtime(true) to geat a float-value and then multiply it by 1000 to get microseconds:

$time = microtime(true)*1000;

take a look at the documentation for more information.


in you JS you could do:

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

this will give you: 1316000000

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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜