How to default value of java.util.Date type parameter in ireport?
I want to set default value of a java.util.Date type parameter to 8 September 2009 in iReport. I set this value in double quote, set it using new java.util.Date(2009,9,8)
, new java.util.Date(1252348200)
and new java.util.Date("08-09-2009")
but it did not work. How can we set these type of values?
使用日历
Calendar c = Calendar.getInstance();
c.set(2009, 8, 8);
Date d = c.getTime();
The Date constructor with three parameters : year, month and day is deprecated . You should use instead the GregorianCalendar class. Howerver, if you really need a Date object, use the getTime() ; method that returns a Date object from a GregorianCalendar instance.
GregorianCalendar gc = new GregorianCalendar(2009, Calendar.SEPTEMBER, 8);
Date myDate = gc.getTime();
According to Nitin Dandriyal's answer:
You can use this code in the Default Value Expression using GroovyShell as follow:
new groovy.lang.GroovyShell().evaluate("Calendar cal = Calendar.getInstance(); cal.set(2009, 8, 8); return cal.getTime(); ")
Update:
链接地址: http://www.djcxy.com/p/3084.html上一篇: 手动设置日期和时间