Fórumok
Convert Timestamp to Date in Velocity
Raphael Crivelli, módosítva 9 év-val korábban
Convert Timestamp to Date in Velocity
Junior Member Bejegyzések: 31 Csatlakozás dátuma: 2012.05.14. Legújabb bejegyzések
Hi
I created for my Web Contents an structure with an date field (ddm-date).
Now, when i create a new Web Content i get the date as an timestamp like this:1421276400000.
How can i convert this 13-digit Timestamp to a date like 15.01.2015 (dd.mm.yyyy)?
Thank you for your help.
Greets Raffi
I created for my Web Contents an structure with an date field (ddm-date).
Now, when i create a new Web Content i get the date as an timestamp like this:1421276400000.
How can i convert this 13-digit Timestamp to a date like 15.01.2015 (dd.mm.yyyy)?
Thank you for your help.
Greets Raffi
David H Nebinger, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
Liferay injects DateTool into the velocity context.
http://help.hannonhill.com/discussions/velocity-formats/5332-formatting-dates-using-datetool
http://help.hannonhill.com/discussions/velocity-formats/5332-formatting-dates-using-datetool
Raphael Crivelli, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Junior Member Bejegyzések: 31 Csatlakozás dátuma: 2012.05.14. Legújabb bejegyzések
Hi David
Thank you for the hint.
I tried the following code in my Velocity ADT:
But on my frontend the variable $display will be displayed.
Do you see an error in the code above?
Thank you.
Thank you for the hint.
I tried the following code in my Velocity ADT:
#set ( $date = "1421276400000" )
#set ( $dateFormat = $_DateTool.getDateFormat("MM-dd-yyyy", $_DateTool.getLocale(), $_DateTool.getTimeZone()) )
#set ( $date = $dateFormat.parse($date) )
#set( $display = $_DateTool.format('medium', $date) )
<span>$display</span>
But on my frontend the variable $display will be displayed.
Do you see an error in the code above?
Thank you.
David H Nebinger, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Liferay Legend Bejegyzések: 14919 Csatlakozás dátuma: 2006.09.02. Legújabb bejegyzések
You mean except that the timestamp you're providing as $date does not match the format you've requested for $dateFormat?
James Falkner, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Liferay Legend Bejegyzések: 1399 Csatlakozás dátuma: 2010.09.17. Legújabb bejegyzésekRaphael Crivelli:
Hi David
Thank you for the hint.
I tried the following code in my Velocity ADT:#set ( $date = "1421276400000" ) #set ( $dateFormat = $_DateTool.getDateFormat("MM-dd-yyyy", $_DateTool.getLocale(), $_DateTool.getTimeZone()) ) #set ( $date = $dateFormat.parse($date) ) #set( $display = $_DateTool.format('medium', $date) ) <span>$display</span>
But on my frontend the variable $display will be displayed.
Do you see an error in the code above?
Thank you.
How about this (tested on 6.2):
#if (!$entries.isEmpty())
#foreach ($entry in $entries)
<p>$entry.title</p>
<p>$dateUtil.getDate($entry.createDate, "MM-dd-yyyy", $locale)</p>
#end
#end
Raphael Crivelli, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Junior Member Bejegyzések: 31 Csatlakozás dátuma: 2012.05.14. Legújabb bejegyzések
Hi James
Thank you. That's it!
Thank you. That's it!
Cyber Katze, módosítva 9 év-val korábban
You can also use $getterUtil.getLong($someString)
RE: Convert Timestamp to Date in Velocity
James Falkner, módosítva 9 év-val korábban
RE: Convert Timestamp to Date in Velocity
Liferay Legend Bejegyzések: 1399 Csatlakozás dátuma: 2010.09.17. Legújabb bejegyzésekCyber Katze:
1) On LR 6.2 there are no $_DateTool and other objects.
2) u have #set ( $date = "1421276400000" ) and this is STRING, u need convert this value to LONG type.
You can also use $getterUtil.getLong($someString)