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

  • Home
  • SEARCH
  • 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 6985173
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T18:38:47+00:00 2026-05-27T18:38:47+00:00

Code first echo time() . ‘<br/>’; echo date(‘Y-m-d H:i:s’) . ‘<br/>’; date_default_timezone_set(‘America/New_York’); echo time()

  • 0

Code first

    echo time() . '<br/>';
echo date('Y-m-d H:i:s') . '<br/>';
date_default_timezone_set('America/New_York'); 

echo time() . '<br/>';
print_r($timezones[$timezone] . '<br/>');
echo date('Y-m-d H:i:s') . '<br/>';

In the above code the date is printed according to timezone but unix timestamp is same even after setting default timezone

How can we print unix timestamp according to timezone?

  • 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-27T18:38:48+00:00Added an answer on May 27, 2026 at 6:38 pm

    The answer provided by Volkerk (that says timestamps are meant to be always UTC based) is correct, but if you really need a workaround (to make timezone based timestamps) look at my example.

    <?php
    
    //default timezone
    $date = new DateTime(null);
    echo 'Default timezone: '.$date->getTimestamp().'<br />'."\r\n";
    
    //America/New_York
    $date = new DateTime(null, new DateTimeZone('America/New_York'));
    echo 'America/New_York: '.$date->getTimestamp().'<br />'."\r\n";
    
    //Europe/Amsterdam
    $date = new DateTime(null, new DateTimeZone('Europe/Amsterdam'));
    echo 'Europe/Amsterdam: '.$date->getTimestamp().'<br />'."\r\n";
    
    echo 'WORK AROUND<br />'."\r\n";
    // WORK AROUND
    //default timezone
    $date = new DateTime(null);
    echo 'Default timezone: '.($date->getTimestamp() + $date->getOffset()).'<br />'."\r\n";
    
    //America/New_York
    $date = new DateTime(null, new DateTimeZone('America/New_York'));
    echo 'America/New_York: '.($date->getTimestamp() + $date->getOffset()).'<br />'."\r\n";
    
    //Europe/Amsterdam
    $date = new DateTime(null, new DateTimeZone('Europe/Amsterdam'));
    echo 'Europe/Amsterdam: '.($date->getTimestamp() + $date->getOffset()).'<br />'."\r\n";
    ?>
    

    Get the regular timestamp and add the UTC offset

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

Sidebar

Related Questions

when I run this code for the first time <?php session_start(); echo SID; ?>
When the following code is run for the first time, it does not echo
Imagine this as the code from build.xml: <project name=test project> <target name=first> <echo>first</echo> </target>
I'll show some code, first: echo exec(compile\\save.exe Untitled.c tmpUntitled.c); I have a program, named
I've been started studying PHP in my spare time, and the first code example
What is wrong with this code it works the first time then when I
i have this code : <?php echo $_POST['id-input']; $time = time(); $ip=$_SERVER['REMOTE_ADDR']; $userid_c =
Here is the piece of code: session_name('somename'); session_start(); echo 'session name:'.session_name(); The above does
Code first: '''this is main structure of my program''' from twisted.web import http from
I often refactor code first by creating an inner class inside the class I'm

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.