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 5997093
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T00:12:49+00:00 2026-05-23T00:12:49+00:00

I was under the impression that the format() function of the PHP DateTime class

  • 0

I was under the impression that the format() function of the PHP DateTime class exported the timestamp it was initially passed with the correct offset applied to it.

I’ve come to realise that it doesn’t make sense for it to do that. I therefore want to store the timestamp from the database (UTC) in the object along with the user’s timezone, and be able to output it according to whether I want a UTC date or a user timezone adjusted date.

I’ve begun extending the DateTime class to do this but I’m wondering if I’m missing something in either the existing methods in DateTime or the thought process behind why the DateTime class works the way it does.

Presumably I’ll also need a couple of static factory methods which can take a timestamp, timezone and whether the timestamp passed in is a user adjusted timestamp or a UTC timestamp, and be able to make the necessary adjustments to instantiate a standardised DateTime object from the UTC version of the time passed in. In this way I’d be able to throw timestamps around the UI and database and be able to convert between them appropriately.

Is there a simpler way? I’ve seen the date_default_timezone_set function but I want to avoid having that setting affect the whole script, leading to user adjusted times being stored in the DB.

(I’m storing users’ timezones in the DB as the timezone string, such as Europe/Berlin, to pass into the functions from a user session variable. I also intend to store all datetimes as UTC times and leave the server’s php.ini set to UTC as well.)

  • 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-23T00:12:50+00:00Added an answer on May 23, 2026 at 12:12 am

    You can create the DateTime instance, specifying that it is UTC. Then change its timezone to that of the user with setTimeZone().

    $datetime = new DateTime("2011-06-07 12:34:56", new DateTimeZone("UTC"));
    $datetime->setTimeZone(new DateTimeZone("Europe/Berlin"));
    echo $datetime->format(DateTime::RSS);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I was under the impression that I could run it on any machine, but
I'm under the impression that the Dot '.' (wild card) character is dangerous to
I've long been under the impression that goto should never be used if possible.
I was for quite some time under the impression that a for loop could
I was under impression that in F# the following two lines are supposed to
I was under the impression that adding a subview to a view goes like
I have been under the impression that processes on the operating system have three
I was under the impression that not calling Response.Flush would ensure that Connection: Close
One of my co workers is under the impression that when adding an index
I was under the impression that when you use a development provisioning profile for

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.