Reputation: 36957
Well, not sure whats going on. I have been trying to follow by examples I have found here on stack, on google, even an answer someone gave me a week+ ago, which unfortunately I wasn't able to test until today.
Anyway I am attempting to generate a javascript friendly timestamp via php so I can get my times synced up. The best logic I could find overall was something dealing with microtime. However that doesn't seem to work as expected, not even in the slightest.
Right now I am using microtime(true)*1000;
and am getting 1.34899651119E+12
for the result. Did I some how manage to mess up that one tiny line of code, Im not sure.
I should mention that I also tried round(microtime(true) * 1000);
which gave very similar results.
Upvotes: 2
Views: 172
Reputation: 57453
Your code is returning 1349000021801.4
to me (PHP 5.3.15 on Linux 3.4.6 x86_64).
To be on the safe side I'd bite the bullet and manipulate the microtime differently:
list($a, $b) = explode(' ', microtime());
$a = round($a*1000.0);
$c = "$b$a\n";
When you output this string to Javascript, it will contain a "clean" integer.
Upvotes: 2
Reputation: 2077
In javascript you can use Math.round(new Date().getTime() / 1000)
to get the current time in seconds.
In PHP you can use time
function.
Upvotes: 0