View Single Post
  #4  
Old 11-18-2020, 12:54 PM
Kyttias's Avatar
Kyttias Kyttias is offline
Premium Member
 
Join Date: Jan 2014
Posts: 857
Gender: Unknown/Other
Credits: 87,457
Kyttias is on a distinguished road
Default

Usually hosting providers can't or won't change the entire server's timezone, as its usually shared hosting, and they'd rather it be local to timezone the server is physically in.

You can change the default time zone for use in particular code on a particular page but don't expect it to carry between pages without specifically making sure its set. (And, of course, this makes the code local to whatever YOU set it to be, not whatever the timezone it currently is for any viewer, so it'll be off for anyone who doesn't share your timezone. Dynamically getting the appropriate timezone is not quite possible without a bit of hackery, which users will always be able to find ways around, anyway.)

But if it helps your mental math to have things based around your own understanding of what time it is, I don't blame you!

Since you're wanting to display code between particular hours, it's worth noting that hours can be checked between midnight 0000 and the minute just before midnight 2359 -- military time. I'm not sure what exactly you're up to, but I hope this can help!

PHP Code:
date_default_timezone_set('America/New_York');
// echo date('Y-m-d H:i:s');

$currentTime date('Hi');
$breakfastStart "0200"$breakfastEnd "1129";
$lunchStart "1130"$lunchEnd "1559";
$dinnerStart "1600"$dinnerEnd "2129";
$lateStart "2130"$lateEnd "0159";

if( 
$currentTime >= $breakfastStart && $currentTime <= $breakfastEnd ){ 
  
/*BREAKFAST*/
    
$timefor 'Breakfast';
} elseif( 
$currentTime >= $lunchStart && $currentTime <= $lunchEnd ){ 
  
/*LUNCH*/
    
$timefor 'Lunch';
} elseif( 
$currentTime >= $dinnerStart && $currentTime <= $dinnerEnd ){ 
  
/*DINNER*/
    
$timefor 'Dinner';
} else { 
  
/*LATE NIGHT SNACK*/
    
$timefor 'Late Night';

Just know that it won't necessarily make sense to everyone viewing it because they won't be in the same time you are. While you're eating breakfast, they could be eating dinner. Even though its dinner time for them in the real world, on your website it's breakfast time because it is where you are. Hope that makes sense!
__________________
Please do not contact me directly outside of Mysidia.
I also cannot troubleshoot code more than two years old - I legit don't remember it.
Reply With Quote