Advertisement
Venciity

Time Until NY

Aug 13th, 2014
442
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1. <?php
  2. $currentDay = getdate();
  3. $now = $currentDay[0];
  4. $firstDayOfNewYear = mktime(0,0,0,1,1,date("Y")+1);
  5. $leftSeconds = $firstDayOfNewYear - $now;
  6.  
  7. $lastSundayOfMarch = strtotime("last Sunday of March");
  8. $startSummerTime = mktime(3,0,0,3, date('d', $lastSundayOfMarch),date("Y"));
  9. $lastSundayOfOctober = strtotime("last Sunday of March");
  10. $endSummerTime = mktime(3,0,0,10, date('d', $lastSundayOfOctober),date("Y"));
  11.  
  12. if ($startSummerTime <= $now && $now <= $endSummerTime) {
  13.     $leftSeconds -= 3600; // remove 1 hour
  14. }
  15.  
  16. $leftMinutes = (int)($leftSeconds/60);
  17. $leftHours = (int)($leftSeconds/3600);
  18.  
  19. $day  = (int)($leftSeconds / (3600 * 24));
  20. $hours = (int)(($leftSeconds % (3600 * 24)) / 3600);
  21. $minutes = (int)(($leftSeconds % 3600) / 60);
  22. $seconds = (int)(($leftSeconds % 3600) % 60);
  23.  
  24. echo "Hours until new year : $leftHours <br / >";
  25. echo "Minutes until new year : $leftMinutes <br / >";
  26. echo "Seconds until new year : $leftSeconds <br / >";
  27. echo "Days:Hours:Minutes:Seconds $day:$hours:$minutes:$seconds";
  28.  
  29. // check answer here : http://www.timeanddate.com/counters/newyear.html
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement