I have asked aqbout timezones and date/time before but this is a more specific question, more about Objects in PHP.
<?PHP
//set the user's time zone on page load
date_default_timezone_set("America/Los_Angeles");
//convert the timestamp from DB into the user's time
$timestamp = '2008-05-01 13:44:19'; //this would normally be returned from mysql
echo ConvertDateTime($timestamp, "America/Los_Angeles");
//here is the function to convert it
function ConvertDateTime($timeString, $timeZone)
{
if ( $d = new DateTime($timeString) ) {
$d->setTimeZone(new DateTimeZone($timeZone));
return $d->format("Y-m-d H:i:s");
}
return null;
}
?>
Ok this is probably a dumb queston to some but I really do not know a lot or have much experience when it comes to classes and objects, generally on a page for example I will create 1 database object and run every mysql query on the page with that 1 object set. I always think less objects is probably better but I have read on this site that having hundreds of objects would be the same speed and resourses used compared to 1 object, not sure f it's true or not.
My question, in the function above, you can see that a new DateTime object is created everytime the function is called, could be 100 times on some pages in my situation. So should I use like a singlton or even I could set a dattim object 1 time in the header where my database object is set as well or should I just let the function create a ton of object?
Please explain the pros and cons and which I should probably do, appreciate any advice, some may say I am pre-optimizing, well I have been optimizing a current site for over 2 years to get it where I wanted it and now I am re-building that SAME site so I kinda know what userload to expect and stuff and I would rather fix something like this now instead of later.