Jump to content

[SOLVED] Time zones


Mathematicman

Recommended Posts

Hi all

 

I'm still kind of new at php... so this may be a dumb question...

 

I had set up a php document that involved the time...

 

So I put it together something like this:

<?php
$H= date("H")-6;
$col= ":";
$M= date("i");
$T= "$H$col$M";
echo $T;
?>

 

That may not be the best way to do it... but I wasn't getting any error reports that way (and I needed it in a 24 hour format)...

 

My problem/question, is how do I do time zones? the "date("H")-6" thing doesn't work,

at times you get "-3:00", not really useful... so how do I do it so it's on my time zone?

 

Thanks for your help...

 

Link to comment
https://forums.phpfreaks.com/topic/67723-solved-time-zones/
Share on other sites

the time returned $T is the time at the city where your host server located. 

So if your host is in New York, it would return EDT.

 

So for instance, you are living California (time zone -8) and your host server located in NY (time zone -5),  then the offset you need to add to the "hours" would be -8 - (-5) = -3

 

so Base on your code:

<?php
$timeOffset = -3
$H= date("H") + $timeOffset;
$col= ":";
$M= date("i");
$T= "$H$col$M";
echo $T;
?>

 

Be aware the make change to your code if the hours is negative.

 

Link to comment
https://forums.phpfreaks.com/topic/67723-solved-time-zones/#findComment-340260
Share on other sites

Ok... so here's what I have...

 

My time zone is 6 hours from what my server’s time zone is...

So here's my code:

<?php
$timeOffset = -6
$H= date("H") + $timeOffset;
$col= ":";
$M= date("i");
$T= "$H$col$M";
echo $T;
?>

 

It’s 9:14 right now and the page reads "-3:14" is the negative supposed to be there?

Can I change it or is it as good as it gets?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/67723-solved-time-zones/#findComment-342674
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.