论坛

主页 » Liferay Portal » English » Liferay Legacy

组合视图 统一视图 树状图
讨论主题 [ 上一个 | 下一个 ]
toggle
Scott McMasters
velocity templates and dates
2007年1月4日 下午8:35
答复

Scott McMasters

等级: New Member

帖子: 23

加入日期: 2006年12月3日

最近的帖子

I need to be able to format dates in journal entries (such as $reserved-article-display-date) but velocity's DateTool isn't available. I don't know much about velocity. Anyone know offhand how I can do this easily?

Thanks,

Scott
alfonso lopez
RE: velocity templates and dates
2007年8月22日 上午4:50
答复

alfonso lopez

等级: Regular Member

帖子: 136

加入日期: 2007年4月25日

最近的帖子

Did you solve it?
Rasto Rehak
RE: velocity templates and dates
2008年4月26日 下午12:28
答复

Rasto Rehak

等级: Junior Member

帖子: 47

加入日期: 2007年3月8日

最近的帖子

Yes, I did.
$dateTool.format( 'full','short', $dateTool.toDate( "EEE, dd MMM yyyy hh:mm:ss Z" , $reserved-article-display-date.getData()) , $localeUtil.fromLanguageId( $request.locale ) )
Milan Jaroš
RE: velocity templates and dates
2009年1月20日 上午12:04
答复

Milan Jaroš

等级: Regular Member

帖子: 224

加入日期: 2008年8月18日

最近的帖子

Thank you so much.
is it possible to use just
1$locale
instead of
1$localeUtil.fromLanguageId( $request.locale )
?
It's working but I don't know if it is correct.

If you want to display date in another format you can use this:
1$dateTool.format("dd. MM. yyyy / hh.mm:ss",
2  $dateTool.toDate("EEE, dd MMM yyyy hh:mm:ss Z",
3    $reserved-article-modified-date.getData()), $locale)

(for more info see [url=http://velocity.apache.org/tools/releases/1.3/javadoc/org/apache/velocity/tools/generic/DateTool.html#format(java.lang.String,%20java.lang.Object,%20java.util.Locale,%20java.util.TimeZone)]DateTool Velocity Documentation)
Josemar Salles
RE: velocity templates and dates
2010年10月30日 上午8:37
答复

Josemar Salles

等级: New Member

帖子: 12

加入日期: 2010年10月29日

最近的帖子

Hi Scott,
did you solve your problem about formatting?
I have the same question.
Thank you.
Milan Jaroš
RE: velocity templates and dates
2010年11月2日 上午8:21
答复

Milan Jaroš

等级: Regular Member

帖子: 224

加入日期: 2008年8月18日

最近的帖子

Hi,
my script ahead is fine. ;)
... But there is new issue in 6.0.5 . emoticon
David García González
RE: velocity templates and dates
2011年6月17日 上午3:19
答复

David García González

等级: Regular Member

帖子: 127

加入日期: 2009年7月14日

最近的帖子

Yes, you can use DateTool

http://velocity.apache.org/tools/devel/javadoc/org/apache/velocity/tools/generic/DateTool.html

For example to get the actual year:

1$dateTool.get('yyyy')
Sami Laribi
RE: velocity templates and dates
2011年7月15日 上午9:35
答复

Sami Laribi

等级: New Member

帖子: 1

加入日期: 2011年7月15日

最近的帖子

dateTool.toDate() doesn't work for me (Liferay 6.0.6CE - maybe solved in 6.1) when applied to $reserved-article-modified-date.

This things however works fine (using Liferay parsing library instead of velocity's one):
#set ($portalBeanLocator = $portal.getClass().forName('com.liferay.portal.kernel.bean.PortalBeanLocatorUtil'))
#set ($dateFormatFactory = $portalBeanLocator.locate('com.liferay.portal.kernel.util.DateFormatFactoryUtil'))
#set ($indexFormat = $dateFormatFactory.getSimpleDateFormat('EEE, dd MMM yyyy hh:mm:ss Z'))
#set ($modified_date = $indexFormat.parse($reserved-article-modified-date.getData()))
$dateTool.format("dd MMM yyyy 'à' HH:mm:ss",$modified_date)


It converts "Thu, 14 Jul 2011 14:47:32 +0000" into "14 juil. 2011 à 14:47:32" (french).