フォーラム

ホーム » Liferay Portal » English » Liferay Legacy

構造的に表示 平面上に表示 ツリー上に表示
スレッド [ 前へ | 次へ ]
toggle
Scott McMasters
velocity templates and dates
2007/01/04 20:35
答え

Scott McMasters

ランク: New Member

投稿: 23

参加年月日: 2006/12/03

最近の投稿

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/08/22 4:50
答え

alfonso lopez

ランク: Regular Member

投稿: 136

参加年月日: 2007/04/25

最近の投稿

Did you solve it?
Rasto Rehak
RE: velocity templates and dates
2008/04/26 12:28
答え

Rasto Rehak

ランク: Junior Member

投稿: 62

参加年月日: 2007/03/08

最近の投稿

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/01/20 0:04
答え

Milan Jaroš

ランク: Expert

投稿: 269

参加年月日: 2008/08/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/02 8:21
答え

Milan Jaroš

ランク: Expert

投稿: 269

参加年月日: 2008/08/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/06/17 3:19
答え

David García González

ランク: Regular Member

投稿: 127

参加年月日: 2009/07/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/07/15 9:35
答え

Sami Laribi

ランク: New Member

投稿: 1

参加年月日: 2011/07/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).