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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T14:51:03+00:00 2026-06-12T14:51:03+00:00

I’m trying to figure out how to adapt this code below to offset any

  • 0

I’m trying to figure out how to adapt this code below to offset any user’s timezone.

function now($format = 'Y-m-d H:i:s'){
    return @date($format,mktime());
}

I used this below to adjust for my local time

function now($format = 'Y-m-d H:i:s'){
    return @date($format,mktime() -3600);
}

but I need to adjust it dynamically to the user’s.

EDIT: I have the user define their timezone via a dropdown in a form, saving it to the DB, such as “America/Los_Angeles”.

Any ideas?

  • 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-06-12T14:51:04+00:00Added an answer on June 12, 2026 at 2:51 pm

    It will probably be a very good idea to use the DateTime objects that PHP provides. It promises to deal with time zones as well:

    // Current date/time in the specified time zone.
    $date = new DateTime(null, new DateTimeZone('Pacific/Nauru'));
    echo $date->format('Y-m-d H:i:sP') . "\n";
    

    (Code from the doc page http://de3.php.net/manual/en/datetime.construct.php)

    To get any information about the selected time zone, DateTimeZone offers access to the timezon database information via methods like getTransitions() (you’ll get an array with the offsets for every time known, please see the example on http://de3.php.net/manual/en/datetimezone.gettransitions.php), and getOffset() (which needs the time the offset is asked for, see http://de3.php.net/manual/en/datetimezone.getoffset.php).

    So basically there is no such thing as “the offset in seconds”, because this value changes depending on a) the time you are asking for, because stuff like daylight saving time will affect it over time, and b) the time you are asking it, because any changes to the timezone is affected by local legislation, not unchangeable natural law.

    You are on the right way to store a universal time that can be transformed to local time when necessary, but I would suggest not trying to do it yourself, but to make use of what PHP has to offer. It’ll take you less time to code.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
I am trying to understand how to use SyndicationItem to display feed which is

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.