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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T06:40:18+00:00 2026-05-21T06:40:18+00:00

Possible Duplicate: How can I determine a web user's time zone? Which is the

  • 0

Possible Duplicate:
How can I determine a web user's time zone?

Which is the best way to do this ? php or javascript.Can someone provide me with some snippets ? thanks.

  • 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-21T06:40:19+00:00Added an answer on May 21, 2026 at 6:40 am

    This will get you the timezone as a PHP variable.
    I wrote a function using jQuery and PHP. This is tested, and does work!

    On the PHP page where you are want to have the timezone as a variable, have this snippet of code somewhere near the top of the page:

    <?php    
        session_start();
        $timezone = $_SESSION['time'];
    ?>
    

    This will read the session variable "time", which we are now about to create.

    On the same page, in the <head> section, first of all you need to include jQuery:

    <script type="text/javascript" src="http://code.jquery.com/jquery-latest.min.js"></script>
    

    Also in the <head> section, paste this jQuery:

    <script type="text/javascript">
        $(document).ready(function() {
            if("<?php echo $timezone; ?>".length==0){
                var visitortime = new Date();
                var visitortimezone = "GMT " + -visitortime.getTimezoneOffset()/60;
                $.ajax({
                    type: "GET",
                    url: "http://example.com/timezone.php",
                    data: 'time='+ visitortimezone,
                    success: function(){
                        location.reload();
                    }
                });
            }
        });
    </script>
    

    You may or may not have noticed, but you need to change the url to your actual domain.

    One last thing. You are probably wondering what the heck timezone.php is. Well, it is simply this:
    (create a new file called timezone.php and point to it with the above url)

    <?php
        session_start();
        $_SESSION['time'] = $_GET['time'];
    ?>
    

    If this works correctly, it will first load the page, execute the JavaScript, and reload the page. You will then be able to read the $timezone variable and use it to your pleasure! It returns the current UTC/GMT time zone offset (GMT -7) or whatever timezone you are in.

    You can read more about this on my blog

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

Sidebar

Related Questions

Possible Duplicate: Best way to determine if two path reference to same file in
Possible Duplicate: In Java, what is the best way to determine the size of
Possible Duplicate: Best way to determine if two path reference to same file in
Possible Duplicate: Can you animate a height change on a UITableViewCell when selected? This
Possible Duplicate: Can Read-Only Properties be Implemented in Pure JavaScript? I have an Object
Possible Duplicate: How can I pre-set arguments in JavaScript function call? (Partial Function Application)
Possible Duplicate: How can I convert ereg expressions to preg in PHP? I need
Possible Duplicate: How can I access local scope dynamically in javascript? Hi all. We
Possible Duplicate: How can I determine if a geopoint is displayed in currently viewable
Possible Duplicate: How can I get the name of function inside a JavaScript function?

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.