PHP for echo current hour in specific time zone


#1

Hello, I want to set the minTime to current hour in the UTC-8:00 time zone, if the minTime value is null (or “”). If current time is 10:10, then it should be showing 11:00. How can I do that in php? This is a WP form plugin using jQuery Timepicker to show the dropdown of time options. Here is the original code:

				$data_settings = json_encode(array(
					"format"  => isset($data->format) ? $data->format : $options["timepicker_format"],
					"minTime" => isset($data->minTime) ? $data->minTime : "",
					"maxTime" => isset($data->maxTime) ? $data->maxTime : "",
					"steps"   => isset($data->steps) ? $data->steps : ""
				));

I try to add the following codes below the above code, but it still falls back to the default setting (showing 00:00 am, not current hour)

date_default_timezone_set('America/Los_Angeles');
$current_time = date('h') ;
					
	if ( $data_settings["minTime"] == "") {
		$this => isset($data->minTime) ? $data->minTime : $current_time
	}

Thanks alot


#2

Why are you trying to complicate this so much?

Just do it like this :slight_smile: :

<?php 
 date_default_timezone_set('America/New_York');
 $date= date('m-d-Y') ;
 ?>

Always you need to try to find the easiest way to do something!

Have a nice day!