Link to home
Start Free TrialLog in
Avatar of rgb192
rgb192Flag for United States of America

asked on

a small amount of code, but not so much as to alter other commands

without changing php.ini or another permanent but more difficult solution
please tell me how to change

date('l jS \of F Y h:i:s A')

add more code to change to eastern standard time zone

date_default_timezone_set('America/New_York';)
works but
not my code I just want to create one command to see if code is continuously working

and
date_default_timezone_set('America/New_York';)
would alter the log file which I didnt create
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Not 100% sure I understand the question, but this might be a strategy.  You can retrieve the current settings with date_default_timezone_get().  Save this value in a variable.  Then set the Eastern time zone, recover the formatted date() and store the date string in a variable.  Then set the original timezone back.
http://iconoun.com/demo/temp_rgb192.php
<?php // demo/temp_rgb192.php

/**
 * http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28663001.html
 */
error_reporting(E_ALL);

function other_date($z = 'America/New_York', $p = 'l jS \of F Y h:i:s A')
{
    $d = date_default_timezone_get();
    date_default_timezone_set($z);
    $r = date($p);
    date_default_timezone_set($d);
    return $r;
}

echo '<pre>';
echo PHP_EOL . "LOCAL: " . date('c');
echo PHP_EOL . other_date();
echo PHP_EOL . "LOCAL: " . date('c');

Open in new window

Avatar of rgb192

ASKER

so this function sets the local time and then sets it back to whatever time that code had previously
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of rgb192

ASKER

thanks