Home:ALL Converter>Date reading the wrong time zone

Date reading the wrong time zone

Ask Time:2015-08-22T04:07:26         Author:Paul

Json Formatter

I have the following date function:

function fixDate($strDateTime) {
 $strFormat = 'M, j, Y';
    $strFormatTime = '\a\t g:ia';
    $intTimeStamp = strtotime($strDateTime);
    $strDate = date($strFormat, $intTimeStamp);
    $strTime = date($strFormatTime, $intTimeStamp);

    if($strDate == date($strFormat)) {
        return "Today " . $strTime;
    }
    elseif($strDate == date($strFormat, strtotime('yesterday'))) {
        return "Yesterday " . $strTime;
    }
    else {
        return " on " . $strDate . " " . $strTime;
    }
}

I'm not sure if it is my date function that is causing this or the way my database is structured, but the date on my pages is reading AM when it is supposed to be PM. It is also reading US - Central time, when I need it to be US - Eastern time. I have the dates stored in phpmyadmin as the Date category.

How can I change the date so that is reads as US - Eastern time?

Author:Paul,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32148505/date-reading-the-wrong-time-zone
Kevin Seifert :

I always set the default time zone to GMT\n\n# store all data internally as GMT:\n\n# local tz 1 \\\n# local tz 2 + <-> webservice.php <-> gmt tz\n# local tz 2 /\n\ndate_default_timezone_set('Zulu');\nif( ! defined( 'DATE_FORMAT' ) ) define ('DATE_FORMAT', 'Y-m-d H:i:s');\n\n\nThen render GMT to the local timezone in the \"view\" layer. Local time zones are a major pain to deal with, especially with daylight savings time. :-)\n\n#####################################################\n# TIME UTILS\n#####################################################\n\n# STORE ALL TIME DATA AS GMT, ALONG WITH THE ORIGINAL TIME ZONE\n\n\n# format date string referencing one timezone to another timezone, eg\n# 'Zulu' -> 'America/Chicago'\n# internally, store all data as GMT,\n# where each person has a different view of data\n# NOTE: full datetime is require, because of dst\nfunction datetime_convert( $datestr, $from, $to, $format = null ) {\n\n if ( ! $from ) {\n error_log( \"no timezone 'from'\" );\n return $datestr;\n }\n\n if ( ! $to ) {\n error_log( \"no timezone 'to'\" );\n return $datestr;\n }\n\n if ( ! $format ) {\n $format = DATE_FORMAT; # defined above\n }\n\n $date = date_parse( $datestr );\n #print_r( $date );\n\n $dtime = new DateTime();\n\n # input in $from timezone\n $dtime->setTimeZone(new DateTimeZone($from));\n $dtime->setDate($date['year'],$date['month'],$date['day']);\n $dtime->setTime($date['hour'],$date['minute'],$date['second']);\n\n # output in $to timezone\n $dtime->setTimeZone(new DateTimeZone($to));\n $newdatestr = $dtime->format($format);\n\n return $newdatestr;\n}\n\n\n# convert dates with a GMT offset to offset == 0\n# 2012-01-20T15:52:22.000-05:00 -> 2012-01-20T20:52:22.000Z\nfunction datetime_normalize( $datestr ) {\n $dtime = new DateTime( $datestr );\n $dtime->setTimeZone(new DateTimeZone('Zulu'));\n $newdatestr = $dtime->format(DATE_FORMAT);\n return $newdatestr;\n}\n\n# convert a local time to GMT\nfunction datetime_to_gmt( $datestr, $from, $format = null ) {\n return datetime_convert( $datestr, $from, 'Zulu', $format );\n}\n\n# convert a GMT time to local\nfunction datetime_to_local( $datestr, $to, $format = null ) {\n return datetime_convert( $datestr, 'Zulu', $to, $format );\n}\n",
2015-08-21T20:42:00
yy