加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

Groovy / Grails日期课程 – 获取每月的日期

发布时间:2020-12-14 16:30:50 所属栏目:大数据 来源:网络整理
导读:目前我正在使用以下代码来获取Groovy中的年,月,日,小时和分钟: Date now = new Date()Integer year = now.year + 1900Integer month = now.month + 1Integer day = now.getAt(Calendar.DAY_OF_MONTH) // inconsistent!Integer hour = now.hoursInteger minu
目前我正在使用以下代码来获取Groovy中的年,月,日,小时和分钟:

Date now = new Date()
Integer year = now.year + 1900
Integer month = now.month + 1
Integer day = now.getAt(Calendar.DAY_OF_MONTH) // inconsistent!
Integer hour = now.hours
Integer minute = now.minutes
// Code that uses year,month,day,hour and minute goes here

在这种情况下,使用getAt(Calendar.DAY_OF_MONTH)表示该月的某一天似乎有点不一致.有没有更短的方法来获得当月的日期?

解决方法

如果将以下内容添加到代码中,则应将该月的日期指定为整数日:

Integer day = now.date

这是一个独立的例子:

def now = Date.parse("yyyy-MM-dd","2009-09-15")
assert 15 == now.date

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读