1

I want to convert a Java timestamp into a php timestamp. I have a java code that creates a JSON Object and send the content of this object to a php-page, which should store them into a database.

My problem is, that the timestamps are different.

Java:

Wed Dec 14 14:06:07 CET 2016

The output (as long converted):

1481720767015

On php I tried two different solutions:

PHP:

echo date('d.m.Y H:i:s', intval("1481720767015")/1000);
echo "<br>".gmdate('d.m.Y H:i:s', intval("1481720767015")/1000);

The output:

14.12.2016 08:06:07
14.12.2016 13:06:07

So how can I change the timezone to get the second output to the right time/timezone?

2 Answers 2

1

There is a similar problem here : PHP date(); with timezone?

And the solution is - you need to pass the timezone when creating the date object like below :

$tz = 'Europe/London';
$timestamp = time();
$dt = new DateTime("now", new DateTimeZone($tz)); //first argument "must" be a string
$dt->setTimestamp($timestamp); //adjust the object to correct timestamp
echo $dt->format('d.m.Y, H:i:s');
Sign up to request clarification or add additional context in comments.

2 Comments

thank you. I found another solution: $time = gmdate('d.m.Y H:i:s', intval("1481720767015")/1000); $time = date('d.m.Y H:i:s', strtotime($time)+60*60);
Your example does not use any timezon but directly use some raw interval ;)
0

thank you. I found another solution:

$time = gmdate('d.m.Y H:i:s', intval("1481720767015")/1000);
$time = date('d.m.Y H:i:s', strtotime($time)+60*60);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.