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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T20:56:55+00:00 2026-06-05T20:56:55+00:00

I have a little snippet that formats a date for a timestamp like this:

  • 0

I have a little snippet that formats a date for a timestamp like this: (YYYY-MM-DD H:M:S T ) Ex: 2011-09-29 17:00:46 EST or 2011-09-29 17:00:46 EDT

I would like convert EST and EDT to ET and show ET instead, so the users don’t bother about Dayligt savings. How do I do that?

    $timeZone = new DateTimeZone('America/New_York');
    $processedDate = str_replace(".000000", "", $timestamp);
    $dateTime = new DateTime($processedDate, new DateTimeZone('GMT'));
    $dateTime->setTimezone($timeZone);
    $processedDate = $dateTime->format('Y-m-d H:i:s') . ' ' . $dateTime->format('T');
    echo processedDate;
  • 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-05T20:56:57+00:00Added an answer on June 5, 2026 at 8:56 pm

    The thing that you want to do is not practical and will lead to your users hating you.

    The entire reason behind the named time zones is to accurately represent local time. Representing “Standard” time as a local time when that local area is inside DST is objectively incorrect. Anyone inside that time zone that reads the time is going to be misinformed.

    If you need to store and work with dates and times that ignore time zones, then use UTC for that purpose, i.e. storage and normal math. It’s worth remembering that even the good old Unix timestamp is “seconds past midnight, January 1, 1970, UTC”.

    If you need to represent times local to the user, then you should allow them to pick their local time zone, and convert it on display. Modern PHP’s DateTime and DateTimeZone make this dead-simple. From the interactive prompt:

    php > $utc = new DateTimeZone('UTC');
    php > $amla = new DateTimeZone('America/Los_Angeles');
    php >
    php > $two_past_midnight = new DateTime('2011-04-05 00:02', $utc);
    php > $two_past_midnight->setTimeZone($amla);
    php > echo $two_past_midnight->format('Y-m-d H:i:s');
    2011-04-04 17:02:00
    

    No mess, no fuss. It took care of the math for us when we switched the time zone.

    In the alternative, if you really, really, really want to flatten out DST timezones, look at getTransitions and getOffset in combination with the various timezone date() formats, I in particular. You can poke and prod at the resulting information to find when the “standard” version of any DST zone next transitions and adjust it accordingly. Remember that different areas transition at different times, and not all areas transition by the same amount … and some don’t transition at all. I think someone mentioned Indiana already.

    Normally I’d also provide sample code here, but date math fills me with an insatiable thirst for violence. Whoever decided that 60, 60, 24, 7, 4-6, 12 and 52 were acceptable ways to think about times and dates were evil, evil people. Thankfully they’ve all been dead for between hundreds and thousands of years.

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

Sidebar

Related Questions

hi i have this little snippet of code i wrote that checks to see
I have this cool little snippet that I found, which adds a shadow to
I have taken this little snippet straight out of some code I'm working on:
I have set up a little snippet that will take an autoresponder code for
I have this little piece of code that just checks for a particular text
Say I have this little snippet: <p data-color=red>Hello world</p> An I want to set
I have this simple little JavaScript snippet to try and protect my email address
I've got this little snippet that I use for row highlighting on an XSLT
I have a little snippet that grab's the filename, including the extension. $currURL =
I have a little jQuery snippet that works, but in order to improve my

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.