Jump to content

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


bartelsmedia
 Share

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?

Link to comment
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

image.png.9fd220608b7cd29c627b555aa5758b61.png

  • Like 4
Link to comment
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
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...