How to get local systems time without setting timezone

Hi,

I need a way of getting the local systems time without setting timezone.

I use PHP in CLI on windows for scripting tasks. I need this script to write a log, and would like to write systems local date and time, without having to set the timezone.
If I don’t set the timezone, I get this warning:

Warning: date(): It is not safe to rely on the system’s timezone settings. You are required to use the date.timezone setting or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected the timezone ‘UTC’ for now, but please set date.timezone to select your timezone. in C:\data\development\crons.php on line 2763

The code looks like this:

<?php define('WRITE_LOG', true); define('LOG_FILE', '.\\logfile.txt'); function echoTime($str) { $str = date('Y-m-d H:i:s').' '.$str."\r\n"; echo $str; if (WRITE_LOG) { if ($fp = fopen(LOG_FILE, 'a')) { fwrite($fp, $str); fclose($fp); } } } echoTime(‘Script started’); ?>

Any ideas are more than welcome.

Not sure I understand the problem. You just configure your php.ini to match the timezone used by the server?

I use PHP as a scripting engine from the commandline running scripts like this:

php.exe -n -f crons.php

In the folder I have:

crons.php
php.exe
php5.dll

I need to run the script on machines in different timezones and would like the date and time to match the local systems without having to configure the timezone on each system.

You might want to check out gmdate (http://us2.php.net/manual/en/function.gmdate.php

The U.S. Military uses Greenwich Mean Time (GMT) when they go on long missions.

Sponsor our Newsletter | Privacy Policy | Terms of Service