PHP return time knowing GMT off-set.

Posted on 2007-10-02
Last Modified: 2013-12-13
I need to show the time where I know the GMT offset. I can not use local time because I am not in the same location as the time I am trying to show. For example, I have a location that has (-4) GMT offset. How do I show the actual time there at this moment?

Thanks in advance.
Question by:td234
    LVL 13

    Accepted Solution

    You've actually got a plethora of ways to do this, which is always nice. You can use date($pattern, strtotime('+2 hours')), and that will show the time at a location 2 hours ahead of your server's default time zone. Change that function to be plus or minus however many hours you need.

    As an alternative, you could just change your server's time zone if you access to you php.ini file. This would affect more than just your one script, so that may be great or it may be a bit much.

    Another option is to programatically change your server's default time zone for just the scope of your current script. You need at least php 5.1 to do this. Here's the docs:
    LVL 2

    Author Comment


    Yes, changing the timezone for the server is not an option. I use date all the time to I understand how to set the time using strtotime and even mktime, but I am not adjusting from localtime, but from GMT.

    I was hoping I could just something like date("H;i",gmmktime("H")$offset) but this does not seem to work like I expect.

    I have read the "date_timezone_set" and I will play with that, but was hoping to get the time I need without changing a global variable like the timezone.


    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Join & Write a Comment

    Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    The viewer will learn how to count occurrences of each item in an array.
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    732 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    19 Experts available now in Live!

    Get 1:1 Help Now