This question already has answers here:
Timestamp between Javascript and PHP
(3 answers)
Closed 9 years ago.
I'm getting different values for timestamp using javascript and PHP when code is executed almost at the same time.
using Javascript Date.getTime(), i get
1375228800000
for timestamp while at the same time PHP reports
1375233890
as timestamp from a call to time().
The first ten digits are close but the timestamp from javascript has extra 3 digits (000) which I think is causing PHP to return the date as 1996-08-05 17:08:40 instead of 2013-08-31.
I'm running Javascript and PHP on the same machine.
Why is Javascript adding extra digits (000) and how can I solve this problem? Please help.
JavaScript measures time in milliseconds, not in seconds. Just divide by 1,000.
Related
This question already has answers here:
Working with large numbers in PHP
(8 answers)
Closed 3 years ago.
I searched and I found that I can use number_format function in php. But it can't even store 1 million digits . I am getting output as inf.
Can someone help me please. If it's not possible in php then can it be done in C++ or Java ?
Update: I am using GMP but when I run script browser sent me response as "this site can't be reached, connection was reset". I disabled max execution time but it gives me same error.
What should I do? Do I need to do any other changes in configuration?
There is bigint choice in phpmyadmin
Laravel has that too, and you can do it in terminal
bigint is great but rarely used
Updated
you can use float and set value limit
In this picture I used float and defined the value limit to 20
Hope that helps
This question already has answers here:
Timezone conversion in php
(9 answers)
Closed 8 years ago.
Can someone explain why the following doesn't work?
I have a PHP script that runs on a shared hosting account. The script should output my local time (for the time zone where I'm located, i.e. GMT-8:00, or PST.)
I'm reading documentation for time() PHP method that is supposed to return a Unix timestamp in UTC (or GMT). OK, good. So I need to subtract 8 hrs to get my local time, right?
So I'm doing this:
echo(date("n/j/Y, g:i:s A", time() - 28800)); //8hrs = 28800 seconds
But I'm getting time that is 5 hrs behind!
What can be wrong in a one-line statement as such?
PS. Sorry, if I'm asking the obvious. I'm coming from the world of .NET. I'm new to PHP.
PHP's time() function will always return seconds since the epoch. The culprit for getting unexpected behavior is actually the date() function.
PHP's date() function will automatically convert the date to the current default timezone of PHP, which must be GMT - 3. This is why when you subtract 8 hours you're 5 hours behind.
Instead of using date(), you probably want to check in to gmdate(). Something like:
echo(gmdate("n/j/Y, g:i:s A", time() - 28800));
may be what you need.
This question already has answers here:
how to convert php date formats to GMT and vice versa?
(3 answers)
Closed 9 years ago.
This may be a duplicate but I can't seem to find what I'm looking for.
I want to store dates given by the client in UTC. I have a javascript library that detects the client's timezone and I'm sending the timezone name (e.g. America/Halifax) to the server with the rest of the form data.
I've been searching now for the php functions that I can use to take the date entered and the timezone and convert it to UTC.
I think gmdate is the correct function but how do I use the date entered and the timezone with gmdate?
Try setting date_default_timezone_set('America/Halifax') at the top of your script.
http://php.net/manual/en/timezones.php
This question already has answers here:
Warning: Massive error in json_encode()
(3 answers)
Closed 8 years ago.
I have a weird (and rather frightening) problem with Ajax.
I'm returning 3 large integers from PHP back to Javascript (jQuery):
9849933840800076
9717106838244944
9261288452893495
But recieve:
9849933840800076
9717106838244944
9261288452893496
Notice the last digit in the third integer - WTF ?!?
- I'm logging everything, and am certain it's not my code doing it!
And returning them as strings instead does solve the problem, but still...
It would be nice to get an explanation - and some sleep : )
My fault, sorry. (and thank you, Pekka)
JS "looses precision" on integers larger than 2^53 (+/- 9007199254740992)
- Back to the wriggleroom..
in these kind of cases you can always return the numbers as strings and convert them in the js
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Unix timestamp before 1970 (even before 1700), using PHP
as you know we have date element in HTML5,It can return something like it 1000-10-05,now I need to make this as time stamp,I try to do it by mktime() but It doesn't return true value.
now How can I do that?
mktime() is timestamp based. On 32 bit systems, timestamps can't reach dates that far back - a signed int can reach from ca. 1900 to 2038.
If you need to do operations with pre-1900 dates, consider using the DateTime library instead, available in PHP 5.2 and newer. It works with 64-bit data internally and can manage any date.
use
strtotime($yourHTML$DateString);
If your problem is not the timestamp range issue as discussed, try strtotime instead of mktime.
strtotime('1000-10-05') must do it. but it supports only 1970 and >