1

I'm working on a podcast (on-the-road events) that contains future dates and different time zones.

<pubDate>Wed, 14 Nov 2012 19:00:00 EST</pubDate>
<pubDate>Wed, 25 Jul 2012 19:00:00 CDT</pubDate>
<pubDate>Thu, 29 Mar 2012 19:00:00 MDT</pubDate>

When I parse it with PHP4 (note PHP4), using date() and strtotime(), it adjusts the information and outputs it in the current timezone of the server (including daylight saving time changes).

Code...

date("g:ia T", strtotime($item->pubDate));

Example...

<pubDate>Thu, 29 Mar 2012 19:00:00 MDT</pubDate> outputs 8:00pm CDT

The expected output is 7:00pm MDT

Again, I'm using PHP4, so I can't do DateTime()-type stuff.

Basically, I just want it to just return the characters, instead of interpreting the characters. Maybe I shouldn't use date() or strtotime() at all, but I'm not sure of another way to turn Wed into Wednesday, 19:00:00 into 7:00pm, etc.

KatieK
  • 13,586
  • 17
  • 76
  • 90
doubleJ
  • 1,190
  • 1
  • 16
  • 29
  • I've tried doing this by exploding pubDate, but it would be so much nicer to be able to output in a more human-readable format. – doubleJ Mar 20 '12 at 20:37
  • 1
    Do all of them output in CDT (presumably because that's the server's timezone)? I think you can call `putenv('TZ=MDT');` before calling `date()` to change that environment var. So if you parse out the timezone and use it like that, I _think_ it could work. – Wiseguy Mar 20 '12 at 20:47
  • I'll look into it. I did realize that I could still use date() for everything except the time, so Thu is Thursday and such. Unfortunately, it would be a pain to if(substr($item->pubDate,17,5)=="19:00") $time="7:00pm"; and such. – doubleJ Mar 20 '12 at 20:57
  • It looks like TZ=MDT (or whatever other time zone) isn't working properly. TZ=America/Chicago (or whatever city is associated with whatever time zone) does. That is kind of lame, as I have to if($bleh == "MDT") putenv("TZ=America/Denver") and such. Is there a simpler way? – doubleJ Mar 20 '12 at 21:21
  • Bummer. Well, if you had to do it manually, one way to shorten it a little would be to grab just the hour and do something like: `$ampm = ($hour < 12 ? 'am' : 'pm'); $newhour = $hour % 12;`. Hope that helps. (FYI, when you reply by comment, start it with "@Wiseguy" so the system will notify me.) – Wiseguy Mar 20 '12 at 21:55
  • @Wiseguy I did get it working, though. Here is the updated code (if there is a better way to format it, please let me know). `$explodedpubDate = explode(" ", $item->pubDate); $pubDatetimezone = $explodedpubDate[5]; if($pubDatetimezone == "PST" || $pubDatetimezone == "PDT") putenv("TZ=America/Los_Angeles"); if($pubDatetimezone == "MST" || $pubDatetimezone == "MDT") putenv("TZ=America/Denver"); if($pubDatetimezone == "CST" || $pubDatetimezone == "CDT") putenv("TZ=America/Chicago"); if($pubDatetimezone == "EST" || $pubDatetimezone == "EDT") putenv("TZ=America/Montreal");` – doubleJ Mar 20 '12 at 22:03
  • Another point of reference... The podcast actually needs the correct timezone (CST or CDT). The rendered time will be an hour off if pubDate is CST and we're actually in CDT. – doubleJ Mar 20 '12 at 22:45
  • While `putenv("TZ=America/Chicago");` worked with linux/apach2/php4, it didn't work with windows/iis7/php5 (not sure why, as putenv() isn't depricated). I did find new php5 code that does the same job, though. `date_default_timezone_set("America/Chicago");` – doubleJ May 01 '12 at 16:40

0 Answers0