Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create Calendar object using SpEL

Given a java.util.Date(), how do you create a Calendar object using the Spring Expression Language?

This one works: <property name="calendarObject" value="#{new java.util.GregorianCalendar()}"/>

but I need to feed the day, month, and year to its constructor from the java.util.Date() date that I have. I would like to use the java.util.Date().getDay() method but apparently it's already deprecated.

I tried using the Calendar.setTime() method but it doesn't work since its return type is void.

like image 453
mpmp Avatar asked Oct 21 '25 18:10

mpmp


1 Answers

You can also call the getTime() method which is inherited like this

value="#{new java.util.GregorianCalendar().getTime()}

and its possible to set a date like this

new java.util.GregorianCalendar(1980,01,01).getTime()
like image 193
emeraldjava Avatar answered Oct 24 '25 07:10

emeraldjava



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!