Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Play Framework date in view

What is the best way to add a dynamic date (year) in a Play Framework view. I want to add a copyright at the bottom of the page, but I do not want to hard code 2011.

<p> &copy; 2011 </p>

How can I get 2011 to always be the current year?

like image 210
Ryan Avatar asked Oct 21 '11 21:10

Ryan


2 Answers

For Play 1.x try this

${new Date().format("yyyy")}

For Play 2.x users, the synyax is subtly different

@(new Date().format("yyyy")) 

It creates the current date, and formats it (using the Format JavaExtension for the Date object).

like image 109
Codemwnci Avatar answered Jan 02 '23 15:01

Codemwnci


Don't forget to add @import java.util.Date in template file for @(new Date().format("yyyy")) to work

like image 32
Api Avatar answered Jan 02 '23 15:01

Api