Axel Benitez
Axel Benitez

Reputation: 25

Format timestamp with PHP

I need to format this -> 1584094135205

I have tried these two functions:

date ("Y-m-d", strtotime (1584094135205))
// 1969-12-31 21:00:00

date ("Y-m-d", 1584094135205);
// 52167-12-11

The value is saved in a database from a Minecraft server when they are registered.

The date that should be output is: 2020-01-12

Upvotes: 1

Views: 165

Answers (1)

gre_gor
gre_gor

Reputation: 6801

Your timestamp is in milliseconds, while date expects it in seconds.

Divide it by 1000.

date("Y-m-d", 1584094135205/1000);
// 2020-03-13

Upvotes: 3

Related Questions