1

I have written the following code:

$timestamp = "1483625713000";
$date = date('d-m-Y', $timestamp);
$time = date('Gi.s', $timestamp);

but the output is not coming as expected: My outputs:

echo $date  //   23-03-48984
echo $time  //   2136.40
abhit
  • 973
  • 3
  • 17
  • 40
  • 1
    How did you generate that timestamp? If you cut off the last 3 0s, it gives a proper timestamp (2017-01-05 09:15:13). – aynber Jan 10 '17 at 16:01
  • but thatsolution is not working for me – abhit Jan 10 '17 at 16:01
  • @anyber u r right maybe i have to check its generation. – abhit Jan 10 '17 at 16:03
  • Note that the unix timestamp can only contain a 32-bit integer. You're overflowing it now, which causes all kinds of chaos. https://3v4l.org/JCIGM – Loek Jan 10 '17 at 16:07
  • 4
    I'm guessing you've got this timestamp from JavaScript? There's a difference, where PHP uses seconds, and JS uses milliseconds. http://stackoverflow.com/questions/7114603/why-dont-php-and-javascripts-timestamps-match – Qirel Jan 10 '17 at 16:15
  • also consider for new users how you define `as expected` – thatsIch Jan 10 '17 at 17:30

1 Answers1

1

Looks like you've got milliseconds in that timestamp. Try this:

$timestamp = 1483625713000 / 1000;
$date = date('d-m-Y', $timestamp);
$time = date('Gi.s', $timestamp);

var_dump($date);
var_dump($time);

Outputs

string(10) "05-01-2017"
string(7) "1415.13"
Chris Sprague
  • 368
  • 1
  • 4
  • 12