Jump to content

Archived

This topic is now archived and is closed to further replies.

OsvaldoM

Zend Framework :: date on one line with timezone set?

Recommended Posts

Hey everyone,

if there is one thing i don't like about Zend Framework is that the date functions are a bit confusing and that it takes a few lines to tackle down what i really need... so i was making this line of code:

 

$date = Zend_Date::now()->get('YYYY-MM-dd HH:mm:ss', 'Europe/Vienna');

 

but i realized it never gets me the timezone i wanted... This doesn't work either:

 

$date = Zend_Date::now()->setTimezone('Asia/Kabul')->get('YYYY-MM-dd HH:mm:ss');

 

Do note this never throws an exception, it outputs the correct time (local) but it's unable to change the timezone of the now() constant.

I've been able to change the timezone with multiple lines of code for now(), but i can't seem to get it on just one...

Is it possible to do it on just one line? or is it just me being lazy?

Thanks in advance for any replies...

Share this post


Link to post
Share on other sites

According to the documentation get() doesn't except a format argument, so I'm not sure why your passing it one, it's second argument is a local also, not a timezone.

 

It's been a long while since Ive bothered with Zend, but looking at the docs it seems that ....

 

$date = Zend_Date::now()->setTimezone('Asia/Kabul');

 

should be all you need.

Share this post


Link to post
Share on other sites

Don't know what happened... but i tried this again today, and it worked perfectly. Probably one of those weird cookie/cache errors was making my script display the local date as i originally had it.

 

$date = Zend_Date::now()->setTimezone('US/Eastern')->get('YYYY-MM-dd HH:mm:ss');

 

That works perfectly as stated by thorpe, hope this helps someone out...

Thanks 4 the reply.

 

And yeah, i format the date via the get function (You ought to never really trust Zend's docs, they are in lack of a ton of info)

Share this post


Link to post
Share on other sites
(You ought to never really trust Zend's docs, they are in lack of a ton of info)

 

I was actually looking at the api docs and source code.

Share this post


Link to post
Share on other sites

×
×
  • 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.