admin管理员组

文章数量:1130349

I have a given time and I'd like to confirm that is AFTER the current time.

$expires_epoch = strtotime($_POST['expiry']);
if($expires_epoch < current_time('mysql')){
...do stuff...

This snippet only works if I set my server to match my local time. That is to say that it's working in UTC time. Any ideas on what to fix? I've tried many alternative to current_time.

I have a given time and I'd like to confirm that is AFTER the current time.

$expires_epoch = strtotime($_POST['expiry']);
if($expires_epoch < current_time('mysql')){
...do stuff...

This snippet only works if I set my server to match my local time. That is to say that it's working in UTC time. Any ideas on what to fix? I've tried many alternative to current_time.

Share Improve this question asked Dec 5, 2018 at 5:52 SalSal 1535 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Please use DateTime::getTimestamp() that returns unix timestamp.

If you want to format the date according to your time zone then you try this.

$datetime = new DateTime("now", new DateTimeZone('America/New York'));

echo $datetime ->format('m/d/Y, H:i:s');

I have a given time and I'd like to confirm that is AFTER the current time.

$expires_epoch = strtotime($_POST['expiry']);
if($expires_epoch < current_time('mysql')){
...do stuff...

This snippet only works if I set my server to match my local time. That is to say that it's working in UTC time. Any ideas on what to fix? I've tried many alternative to current_time.

I have a given time and I'd like to confirm that is AFTER the current time.

$expires_epoch = strtotime($_POST['expiry']);
if($expires_epoch < current_time('mysql')){
...do stuff...

This snippet only works if I set my server to match my local time. That is to say that it's working in UTC time. Any ideas on what to fix? I've tried many alternative to current_time.

Share Improve this question asked Dec 5, 2018 at 5:52 SalSal 1535 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

Please use DateTime::getTimestamp() that returns unix timestamp.

If you want to format the date according to your time zone then you try this.

$datetime = new DateTime("now", new DateTimeZone('America/New York'));

echo $datetime ->format('m/d/Y, H:i:s');

本文标签: dateHow to get Unix Local Time