Forums

Home » Liferay Portal » English » 2. Using Liferay » General

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Umer Sayeed
Date
March 13, 2013 5:33 AM
Answer

Umer Sayeed

Rank: Junior Member

Posts: 51

Join Date: August 8, 2012

Recent Posts

Hi All ,

When i add new item in Shopping portlet, then in database CreateDate and ModifiedDate column date is comming correct but its taking 5hrs back time,suppose if a i add item at 6:00,in database its taking as 12:30.., please help how to solve this.

Thanks
David H Nebinger
RE: Date
March 13, 2013 5:35 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

There is nothing to resolve.

Liferay (as it should) stores dates/times in GMT mode. Users define the TZ they're in, and the GMT should be converted to the user's local time at presentation time.
mohiden abdul kader
RE: Date
March 13, 2013 7:10 AM
Answer

mohiden abdul kader

Rank: Junior Member

Posts: 38

Join Date: August 8, 2012

Recent Posts

David H Nebinger:
There is nothing to resolve.

Liferay (as it should) stores dates/times in GMT mode. Users define the TZ they're in, and the GMT should be converted to the user's local time at presentation time.



Hi ,

I am also facing the same problem .Its not converting into local machine time,So Kindly give your valuable ideas..

Thanks Regards,
Abdul Kader
David H Nebinger
RE: Date
March 13, 2013 9:42 AM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

If you pull a date using SB, the date comes back to you as GMT.

From there you need to access the current user, find their selected TZ (it is directly accessible from the User pojo, getTimeZone()).

From there you'd define your DateFormat (for rendering), and set the timezone on the DateFormat to the user's TZ. When you call the format() method, it will give you a string with the date formatted for the user's timezone.

That's the hard way (all manual), but it works. An easier method would be:

DateFormat df = DateFormatFactoryUtil.getSimpleDateFormat("MM/dd/yyyy hh:mm", user.getTimeZone());

This will give you a date format w/ the timezone assigned that you can then use for rendering the date/time adjusted for each user.
Hitoshi Ozawa
RE: Date
March 14, 2013 3:48 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

If you're only going to be using in one time zone, just set user.timezone property in System-ext.properties.

I've seen some web systems do what liferay does on displaying time in user's timezone but this actually is very confusing because when there's an announcement that something is going to be on xxx date, it's difficult to know which timezone that means. If a timezone is given with the time, I still have to go check World Time page to see what time that is in my timezone.
David H Nebinger
RE: Date
March 14, 2013 4:47 PM
Answer

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 11295

Join Date: September 1, 2006

Recent Posts

We have users spread across the US. We display times in their timezone so they don't have to do the conversions in their heads or look at the world clock. We store our times in GMT so it's an easy one-way conversion. Using a non-GMT timezone, we'd have to convert between two different timezones, and that can get kinda messy (especially w/ DST stuff thrown in).
Hitoshi Ozawa
RE: Date
March 14, 2013 8:14 PM
Answer

Hitoshi Ozawa

Rank: Liferay Legend

Posts: 7949

Join Date: March 23, 2010

Recent Posts

Yes, this is really a localization problem. Some of us only use 1 timezone and it's really confuses users. I think India is in 1 timezone too.
Umer Sayeed
RE: Date
March 14, 2013 10:35 PM
Answer

Umer Sayeed

Rank: Junior Member

Posts: 51

Join Date: August 8, 2012

Recent Posts

hi i found the solution, just write ASIA/KOLKATA in place of GMT in setenv.bat in tomcat server....,


Thanks and Regards,
Ummer
Dave Weitzel
RE: Date
January 6, 2014 7:25 PM
Answer

Dave Weitzel

Rank: Regular Member

Posts: 203

Join Date: November 18, 2009

Recent Posts

hi David
Came across this post when checking on getting dates to display right for user timezones.
DateFormat df = DateFormatFactoryUtil.getSimpleDateFormat("MM/dd/yyyy hh:mm", user.getTimeZone());

is this still the preferred way of doing things?

I would have expected a tagLib to do this and detect if there is a user or not.

Our first multi timezone location is going live and so many dates are not showing right as everything is GMT!

Any new thoughts on this, does GA3 or 6.2 change things do you know?