Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.