How can one set the default time zone for a PHP script using date_default_timezone_set()?
To set the default time zone for a PHP script using date_default_timezone_set(), you need to specify the desired time zone using a valid timezone identifier. This function will set the default time zone used by all date and time functions in the script. It's important to set the default time zone to ensure that date and time calculations are accurate and consistent.
<?php
// Set the default time zone to New York
date_default_timezone_set('America/New_York');
// Now all date and time functions will use the New York time zone
echo date('Y-m-d H:i:s');
?>
Keywords
Related Questions
- How can deprecated functions like mysql_db_query and mysql_result be replaced in PHP 5.4?
- Is it feasible to allow multiple users to access the same encrypted data with separate passwords in PHP, and what are the potential challenges in implementing this?
- What are the potential pitfalls of using the modifier "s" and "U" in regular expressions in PHP?