Unix time of local time with php

Hello,

My local time “Europe/Istanbul”

How do I get the “unix time(1540382318)” of local time with php?
Not server time

Thank you in advance

Need more clarification. Are you talking about when a user did something or converting the timestamp to something more user friendly?

Thank you for the answer,
I’m sorry I do not know english, I’m using google translation.

I’m writing a task scheduler (beginner encoder)
I’m getting unix time in future history, (sample: 2018.11.21, 14:33) unix time(1542807180)
$future_unix_time = “1542807180”;
if(time()<=$future_unix_time)

My country’s time zone +3
Server time zone 0
Receiving -3 hours of unix time with time(), This also works delayed 3 hours
This is not useful: date_default_timezone_set(‘Europe/Istanbul’);

OR Where am I doing wrong?

<?php

$future_unix_time = "1542807180";

$now = new DateTime();
$now->add(new DateInterval('PT3H'));
$check_time = DateTime::createFromFormat('U', $future_unix_time);
if($now->format('U') <= $check_time)
	$state = "less";
else
	$state = "greater";
	
echo sprintf("%s is %s than %s", $now->format('Y-m-d H:i:s'), $state, $check_time->format('Y-m-d H:i:s'));

Thank you very much for Codes,

I’m using my laptop windows 10 and EasyPHP-DevServer-14.1VC9
My virtual server mochahost
My local time: 25-10-2018, 22:54
Your code output: for “mochahost” 2018-10-25 22:54:45 is less than 2018-11-21 13:33:00
No problem on virtual server

My laptop: 2018-10-26 00:54:43 is less than 2018-11-21 13:33:00
2 hours ahead, why did this happen?

I don’t know. The ‘PT3H’ adds 3 hours to the current DateTime object.

I understand, but is it not possible to set this automatically?
Sample: “Europe/Istanbul” such as

This is not useful: date_default_timezone_set(‘Europe/Istanbul’);

You said that wasn’t useful?

Do you want to change the server time, or the time someone has locally or what? I need more information to be more useful.

I want to, Give me local unix time no matter what the server time is.
If not possible, no problem, I use this “PT3H”

Thank you

Local to whom? If everyone is in the same timezone, setting the server time is what you want to do. If not, then setting the server time to UTC and passing in the users local time is what you want to do.

Thank you,
It worked

Sponsor our Newsletter | Privacy Policy | Terms of Service