Jump to content

[SOLVED] getting date in different time zone


hchsk

Recommended Posts

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

Link to comment
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.