Jump to content

Would using "New DateTimeZone" in Hanna code mess up with Processwire core?

Recommended Posts

I want to output the current local (server) time in 12h format.

Would this code interfere with the Processwire core date/time if used in a hanna code?

 $ct = new DateTime("now", new DateTimeZone('Europe/Berlin'));
echo $ct->format('h:i a');

Does "new DateTimeZone" only affect this code or would it change the general timezone of the Processwire core, thus risking messing up database date/time stamps?

Share this post

Link to post
Share on other sites

You're all good - it won't affect the PHP / PW timezone.

You can test stuff like this yourself - you can see that even though it's outputting the current time in Berlin in the first dump, the default timezone is still America/Los_Angeles


  • Like 4

Share this post

Link to post
Share on other sites

Tiny explanation: The new directive only creates a fresh instance of a PHP class in memory, in this case a DateTime and a DateTimeZone object. The latter is initialized to 'Europe/Berlin' and used as the timezone parameter for initializing the DateTime object, which, in turn, is stored in variable $ct. Nothing affects the system.

  • Like 6

Share this post

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...