PHP date_default_timezone_set() function6 Jan 2025 | 1 min read This function sets the default timezone. It is used by all the date and time functions of the PHP. SyntaxParameterstimezone_identifier: The timezone identifier like UTC or Europe/Lisbon. The list of valid identifiers is available in the List of Supported Timezones. ReturnThis function returns FALSE if the timezone_identifier isn't valid. Otherwise, it returns TRUE. Example 1Output: America/chicago Example 2Output: UTC NOTE: UTC is the standard international time that can be set on local time.Example 3Output: The time is 11:29:49pm Next TopicPhp-date-diff-function |
The PHP timezone_name_get() function is used to show name of timezone. Syntax tring timezone_name_get ( DateTimeZone $object ); Parameters object: It is the date and time zone object. Return This function returns array on success or FALSE on failure. Example 1 <?php $timezone=timezone_open("Europe/Paris"); echo timezone_name_get($timezone); ?> Output: Europe/Paris Example 2 <?php $timezone=timezone_open("Africa/Juba "); echo timezone_name_get($timezone); ?> Output: Africa/Juba TopicPhp-timezone-offset-get-function ...
1 min read
The PHP strtotime() function is used to convert an English text datetime into a Unix timestamp. Syntax int strtotime ( string $time [, int $now = time() ] ) Parameters Parameter Description Required/Optional Time Specifies a date/time string Required Now A timestamp that calculate relative dates. Optional Return This function returns a timestamp on success, FALSE otherwise. Example 1 <?php echo(strtotime("now") ....
1 min read
It returns new date and time. Syntax DateTime date_create ( [$time [, timezone]] ); Note : time and timezone are the optional parameters. Return This function returns the DateTime object on success or FALSE on failure. Example 1 <?php $datefind=date_create("2018-7-25 5:0:00",timezone_open("America/Chicago")); echo date_format($datefind,"Y/m/d H:iP"); ?> Output: 2018/07/25 05:00-05:00 Example 2 <?php $date=date_create("2018-07-27"); ...
1 min read
The PHP microtime() function is used to returns the current Unix timestamp with microseconds. Float value is return by this function. Syntax mixed microtime ([ bool $get_as_float = FALSE ] ) Parameters Parameter Description Required/Optional get_as_float specifies that the function should return a float optional Return This function returns a string in the form "msec sec",...
1 min read
This PHP timezone_abbreviations_list() function is used to return an associative array that contains the timezone name, offset and the dst. Syntax array timezone_abbreviations_list(); Return This function returns array on success or FALSE on failure. Example 1 <?php $timezone_abbreviations = timezone_abbreviations_list (); print_r($timezone_abbreviations["acst"]); echo "----------------------------------------------\n"; # Using...
9 min read
This function is used to add the days, months, years to the date. Syntax date_add(object,interval); Parameters Parameter Description object Required. Specifies a DateTime object interval Required. Specifies a DateInterval object Example 1 <?php $datefind=date_create("2018-03-16"); date_add($datefind,date_interval_create_from_date_string("4 days")); echo date_format($datefind,"Y-m-d"); ?> Output: 2018-03-20 Example 2 <?php $date=date_create("2018-12-10"); date_add($date, date_interval_create_from_date_string("2 year ...
1 min read
The date_timestamp_set() function is used to set the date and time based on unix timestamp. It returns a datetime object and unix timestamp represents the date. Syntax date_timestamp_set(object,unixtimestamp); Parameters Parameter Description Required/Optional object Specifies a DateTime object required unixtimestamp Specifies a Unix timestamp representing the date optional Example 1 <?php $date1=date_create(); date_timestamp_set($date1,1533132945); echo date_format($date1,"U = Y-m-d H:i:s"); ?> Output: 1533132945 = 2018-08-01 14:15:45 Example 2 <?php $date=date_create(); date_timestamp_set($date,1533133630); echo date_format($date,"U...
1 min read
The date_time_set() function is used to set the time in a specified format. It returns a datetime object at the end. Syntax date_time_set(object,hour,minute,second); Parameters Parameter Description Required/Optional object Specifies a DateTime object required hour Specifies the hour of the time Specifies the hour of the time minute Specifies the minute of the time required second Specifies the second of the time optional Example 1 <?php $date1=date_create("2018-7-31"); date_time_set($date1,10,24); echo...
1 min read
If any error comes while parsing the date string, this function will show warnings/ errors in output. Syntax date_get_last_errors(); Example 1 <?php date_create('g$%^jngvnk'); print_r(date_get_last_errors()); ?> Output: Array ( [warning_count] => 1 [warnings] => Array ( ...
1 min read
It is used to set a new date and formatting of date is also allowed. It returns a datetime object. Syntax void date_date_set ( DateTime $object, int $year, int $month, int $day ); Parameters Parameter Description object Required. Specifies a DateTime object returned year Required. Specifies the year of the date month Required. Specifies the month...
1 min read
We request you to subscribe our newsletter for upcoming updates.
We provides tutorials and interview questions of all technology like java tutorial, android, java frameworks
G-13, 2nd Floor, Sec-3, Noida, UP, 201301, India