1

I just don't understand GMT on how it works with your php sql server time. How do you relate to your database with the minutes offset? So if this produces -420 minutes how do we relate that to our database time (for example unix time 2016-09-14 22:40:31)(your NOW() time)?

I am just not sure how to implement this in PHP? There is some vague information I have found on how to use it after you get your minutes offset.

`date_default_timezone_set('America/Boise');`

$created=date('Y-m-d H:i:s');

I got the code below from:

https://stackoverflow.com/a/5492192/6173198

function TimezoneDetect(){
    var dtDate = new Date('1/1/' + (new Date()).getUTCFullYear());
    var intOffset = 10000; //set initial offset high so it is adjusted on the first attempt
    var intMonth;
    var intHoursUtc;
    var intHours;
    var intDaysMultiplyBy;

    //go through each month to find the lowest offset to account for DST
    for (intMonth=0;intMonth < 12;intMonth++){
        //go to the next month
        dtDate.setUTCMonth(dtDate.getUTCMonth() + 1);

        //To ignore daylight saving time look for the lowest offset.
        //Since, during DST, the clock moves forward, it'll be a bigger number.
        if (intOffset > (dtDate.getTimezoneOffset() * (-1))){
            intOffset = (dtDate.getTimezoneOffset() * (-1));
        }
    }

    return intOffset;
}
alert(TimezoneDetect()); 
Community
  • 1
  • 1
  • 2
    Oh dear. So many [incorrect assumptions about time zones](http://infiniteundo.com/post/25509354022/more-falsehoods-programmers-believe-about-time#_=_). – Phylogenesis Sep 15 '16 at 14:41
  • 1
    php doesn't change dates/times coming out of mysql. they're just strings.if you get `2016-09-15 08:40:00` out the db, then that's what PHP will send on to the client app. PHP has no native date/time data types, therefore all dates/times are either strings, or simple integers (e.g. unix timestamps) – Marc B Sep 15 '16 at 14:41
  • Where is a good tutorial on it. I couldn't find a very good one to explain it better even in w3schools. I just want to understand how to make my server time be manipulated to look like user's time on their screen. So string "2016-09-15 08:40:00" is the server, yet the user is "2016-09-15 13:40:00". So I thought that was what the time offset was suppose to do (add or subtract time). –  Sep 15 '16 at 15:41

1 Answers1

0

You can use the bellow code to set the time zone:

date_default_timezone_set('Europe/London');

This code will add +1 hour onto the timestamp.

$timestamp= strtotime("+1 hour");

I hope this is what you were asking for.

You can also use the same as what you were using to turn the timestamp into text:

gmdate("H:i", $timestamp);
FluxCoder
  • 1,266
  • 11
  • 22
  • How would you relate this to time zones? They offset it by minutes, strtotime("+420 minutes"), so I believe this would work. Good answer –  Sep 15 '16 at 15:54