Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 524441
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T08:34:06+00:00 2026-05-13T08:34:06+00:00

I have asked aqbout timezones and date/time before but this is a more specific

  • 0

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-&gt;setTimeZone(new DateTimeZone($timeZone));
        return $d-&gt;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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T08:34:06+00:00Added an answer on May 13, 2026 at 8:34 am

    should I use like a singlton

    Singleton are not without problems — for instance, they often make (automated) testing difficult. Which is one of the reasons for which they are less and liked by “big” Frameworks (I’m thinking about Zend Framework and Symfony, which are reducing the number of Singletons for their next major version)

    I could set a dattim object 1 time in
    the header

    Using a global variable / object can go with side-effects, too ; If a variable is meant as “local”, it should be local — code readibily and ability to understand it are generally more important than a fraction of a millisecond.

    For extreme and specific cases, the only (true) solution is to profile : you want your script / application to go faster ? To use less CPU ?

    Then, first of all, profile it ! It’ll help identify bottlenecks — and show you on what you should concentrate.

    Chances are you have plenty of things that could be optimized fastest (i.e. which would take less time to think about, code, and test) — and would get you higher performance gains.

    In the end, you always have to choose between :

    • the best possible performances
    • time it takes to develop / optimize something
    • time it takes to maintain it ; including for someone else than you.

    And, quite often, a new, more powerful server (or a second one) will finally coest less than a couple of weeks spent optimizing to get only 5% !

    (Note I didn’t say you shouldn’t optimize ; but you shouldn’t over-optimize.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already asked about this for android, but I will broaden the question
i have asked a question about manytomanyfield here which i solved but now a
I have tried looking though several of the already asked question about this topic
Many people have asked about Rails hosting on this site, but I'm not familiar
I have asked this question here about a Python command that fetches a URL
I have asked this question about using the a Linq method that returns one
I have asked on here before about mod_rewrite and got the perfect answer but
I have asked the same question before and I found this solution : if
I realize that a billion people have asked about this error, but I've looked
I realize that similar questions have been asked about this before here on SO,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.