Converting Unix Timestamp to PHP Date(), Year doesn't work

Henk1987

I'm trying to convert a Unix Timestamp to a date using php.

But I can't seem to get the Year to work. What am I doing wrong?

Unix Timestamp: 1409522400000

gmdate("d-m-Y", 1409522400000)

PHP date: 27-12-46635

Jerodev

Your unix timestamp is in milisecconds, php uses seconds. Remove the last three zeroes and you get:

date('d.m.Y H:i:s', 1409522400); //01.09.2014 00:00:00



Update: If you are getting the timestamp from an api, you can divide the timestamp by 1000;

$ts = 1409522400000;
date('d.m.Y H:i:s', round($ts / 1000));

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Converting Unix Timestamp to PHP Date(), Year doesn't work

From Dev

PHP Converting A Date to Unix Timestamp

From Dev

DatePipe in Angular doesn't work while converting timestamp to human date formats

From Dev

Converting a UNIX timestamp into a Date object in Elm

From Dev

Converting date with timezone in UNIX timestamp Shell/Bash

From Dev

converting php string with date and time to sql timestamp

From Dev

Converting iso8601 date to unix timestamp in java

From Dev

One hour added when converting date to unix timestamp

From Dev

One hour added when converting date to unix timestamp

From Dev

Converting unix timestamp (length 13) string to readable date in Python

From Dev

Converting time to unix timestamp

From Dev

Unix Timestamp Conversion PHP - Wrong Date

From Dev

Convert real world date into unix timestamp PHP

From Dev

php unix to date not work correctly

From Dev

Converting Timestamp to Date Excel

From Dev

Converting timestamp to date ONLY

From Dev

Converting date (with milliseconds) into timestamp

From Dev

converting date string to timestamp

From Dev

converting unix timestamp to local time

From Dev

CQLSH: Converting unix timestamp to datetime

From Dev

Leap year function doesn't work

From Dev

Leap year function doesn't work

From Dev

SQL Filter doesn't work with past year

From Dev

Converting Unix Date format

From Dev

Converting JSON to XML doesn't work

From Dev

Geocode : converting doesn't work by submitting form

From Dev

Mysql TIMESTAMP trigger doesn't work

From Dev

Converting a timestamp string to UNIX timestamp in MonetDB

From Dev

Unix timestamp wont work