Write a PHP program that will: Obtain the current date and time. Determine if we
ID: 3591728 • Letter: W
Question
Write a PHP program that will: Obtain the current date and time. Determine if we are Daylight Savings Time or not If we are not, display message “It is not daylight savings time”“Daylight savings time starts in: “ dd:hh:mm If it is daylight savings time, display message “It is daylight savings time”“Daylight savings time ends in: “dd:hh:mm Your program should determine the days, hours, and minutes either until daylight savings time or until it ends based on the date the program runs. it should say "It is daylight savings. Daylight savings time ends in: 22 days, 2 hours, 4 minutes"
Explanation / Answer
For the below program time zone assumed is 'America/New_York'.
PHP function date('I', $date) is used to check if current time is daylight saving.
<?php
$date = date_create('America/New_York');
$date-> format('d:m:y:h:i:s');
$timestamp = (int) $date;
$DL = (date('I', $timestamp)); // Checking if the current date is in Daylight saving
$date1 = new DateTime('2017-11-05 02:00:00');
$date_end = new DateTime('2017-03-12 02:00:00');
$date_end_e = $date->diff($date_end);
$date2 = $date1->diff($date);
if ($DL == 0)
{
echo "Its not daylight saving. Daylight saving starts in: ".$date_end_e->d.' days, ', $date_end_e->h.' hours, '.$date_end_e->i.' minutes';
}
else
{
echo "Its daylight saving. Daylight saving ends in: ".$date2->d.' days, ', $date2->h.' hours, '.$date2->i.' minutes';
}
?>
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.