Jump to content

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


OsvaldoM

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

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

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

Link to comment
Share on other sites

  • 2 weeks later...
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.