我必须获取任何一年的最后一个星期四的日期,但我面临的问题是,month of dec'15
最后一个星期四是,31-dec-2015
但我得到24-dec-2015
以下代码:
Date getLastThursday(def month, def year ) {
Calendar cal = Calendar.getInstance();
cal.set( year, month,1 )
cal.add( Calendar.DAY_OF_MONTH, -(cal.get(Calendar.DAY_OF_WEEK )%7+2) );
return cal.getTime();
}
Run Code Online (Sandbox Code Playgroud)
并解释我这段代码如何内部工作?
cal.add(Calendar.DAY_OF_MONTH, -(cal.get(Calendar.DAY_OF_WEEK )%7+2))
我必须在SQL查询的子句中给出值列表,但在检索值[]时,还会出现查询语言无法读取的数据.
例如,我有以下列表:
def val = new ArrayList<Integer>(Arrays.asList(1,2,3,4,5,6,7,8))
Run Code Online (Sandbox Code Playgroud)
在println(val)
输出时,[1, 2, 3, 4, 5, 6, 7, 8]
但在查询中需要它:1, 2, 3, 4, 5, 6, 7, 8
在java中,这个可以工作,System.out.println(val.toString().replaceAll("[\\[\\]]", ""))
但不是在groovy中.我们不能像这样使用集合删除吗?