?
Solved

PHP return time knowing GMT off-set.

Posted on 2007-10-02
2
Medium Priority
?
275 Views
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.
0
Comment
Question by:td234
2 Comments
 
LVL 13

Accepted Solution

by:
MasonWolf earned 2000 total points
ID: 20003743
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: http://us.php.net/manual/en/function.date-default-timezone-set.php
0
 
LVL 2

Author Comment

by:td234
ID: 20005685
Thanks.

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.

Thom
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses
Course of the Month16 days, 3 hours left to enroll

850 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