Skip to content

Instantly share code, notes, and snippets.

@dev-w3
Created September 27, 2022 09:18
Show Gist options
  • Save dev-w3/e0497a9b52bd02e6c0a0c7889973e0e8 to your computer and use it in GitHub Desktop.
Save dev-w3/e0497a9b52bd02e6c0a0c7889973e0e8 to your computer and use it in GitHub Desktop.
change default timezone and check if current time is between two time
<?php
$estTime = (new DateTime('America/New_York'))->format('h:i a');
$current_time = $estTime;
$sunrise = "12:00 am";
$sunset = "03:00 am";
$date1 = DateTime::createFromFormat('h:i a', $current_time);
$date2 = DateTime::createFromFormat('h:i a', $sunrise);
$date3 = DateTime::createFromFormat('h:i a', $sunset);
if ($date1 > $date2 && $date1 < $date3)
{
echo '<h3>System is down for maintenance daily from 12am EST to 3am EST</h3>';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment