hchsk Posted May 2, 2009 Share Posted May 2, 2009 how can i get the date() function to return a time in a different time zone, in this case EDT, America/New_York date_default_timezone_set('EDT'); $nowpub = date("D, j M Y g:i:s"); DateTimeZone('America/New_York'); $nowpub = date("D, j M Y g:i:s"); both of these fail. any ideas/help/suggestions will be greatly appreciated. i do not have access to .ini this must be accomplished within a script Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Try strftime(). Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 still seems to return in the wrong time zone, now -3 hours Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted May 2, 2009 Share Posted May 2, 2009 What php version? What is the current code? strftime() does not take into account the time zone, only language settings, you must still set the time zone before using it. And DateTimeZone is a an class, you don't just call it like a function. Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 Sorry, I meant gmstrftime() with setlocale My apologies. Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 PHP Version 5.2.6 maybe i was confused about strftime use, i will try again, when i looked at the manual i though (wrongly i suppose) that you needed to identify the language settings, not the time zones, haha, and even that only if you wanted to display a textual representation of the month or day Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 i just tried this, still to no avail. am i making a mistake? setlocale(LC_ALL, 'NY_2'); print strftime("%H"); i think my NY_2 may be incorrect, i am unsure of where to find the correct value for my locale (ny ny) Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 ah, sorry, i missed your reply, but i'm still not quite getting it somehow, im now getting a value way off, hours plus 4 and date plus twenty, i dont understand that at all. i think the problem is my setlocale(), ive looked at the links you posted but still dont seem to understand what value i need for EDT, US east, or nyc Quote Link to comment Share on other sites More sharing options...
Ken2k7 Posted May 2, 2009 Share Posted May 2, 2009 I know what you're trying to do, but may I ask what you're using this for? Are you trying to set it to your own timezone or to a client's timezone? Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 2, 2009 Author Share Posted May 2, 2009 im using it to set the value of a $var, in format equivalent to date("D, j M Y g:i:s"); which will be used to post as the pubDate on an RSS item. theres actually another problem there, but one that i can live with not solving, which is when i post a date in proper format EDT, rss changes the time zone to AM. i don't know why, but it would seem to be only in its display, it does not change the actual value, so i can live with it, because its only really crucial when i grab the value with XPATH externally for use in a dynamic script. Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 3, 2009 Author Share Posted May 3, 2009 is there a way to insert javascript into php, that i could use to generate the date and pass it to the php? it needs to be done at that point in the script though Quote Link to comment Share on other sites More sharing options...
hchsk Posted May 3, 2009 Author Share Posted May 3, 2009 i found a way to do it, by using the time() unix epoch and modifying the result as necessary, in my case, like this: $ltime = time() + 3*60*60 ; $mytime = date('D, j M Y g:i:s',$ltime); echo $mytime; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.