Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select the format of $date in vm file?

Tags:

java

velocity

I have a $date defined as "day of week, month day, year" ex: Tuesday, February 26, 2013

I don't know where $date is defined but I like to add the hour to this $date variable, or create a variable with the hour, do you know how can I put it in the .vm file?

like image 764
aF. Avatar asked Feb 26 '13 15:02

aF.


People also ask

How do you format a date?

The international standard recommends writing the date as year, then month, then the day: YYYY-MM-DD. So if both Australians and Americans used this, they would both write the date as 2019-02-03. Writing the date this way avoids confusion by placing the year first.

How to format date in Java?

Java SimpleDateFormat with Locale String pattern = "EEEEE MMMMM yyyy HH:mm:ss. SSSZ"; SimpleDateFormat simpleDateFormat =new SimpleDateFormat(pattern, new Locale("fr", "FR")); String date = simpleDateFormat. format(new Date()); System.

What is velocity .VM file?

Developer file used by Velocity, a Java-based template engine; written using the Velocity Template Language (VTL); contains VTL statements inserted in a normal text document; often used for auto-generating Web source code and class skeletons.

What are Velocity templates?

Velocity is a server-side template language used by Confluence to render page content. Velocity allows Java objects to be called alongside standard HTML. If you are are writing a user macro or developing a plugin you may need to modify Velocity content.


1 Answers

Velocity provides a DateTool class for formatting dates. You would need to put an instance of this class into your velocity context:

context.add("date", new DateTool());

Then you could use a formatting command like:

$date.format('EEE, MMM d, yyyy at ha', $myDate)

to get something like Tuesday, February 26, 2013 at 11AM

like image 59
Stephen Ostermiller Avatar answered Sep 21 '22 05:09

Stephen Ostermiller