15-Groovy-日期和时间
Posted 爱学习de测试小白
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了15-Groovy-日期和时间相关的知识,希望对你有一定的参考价值。
日期和时间
前言
- 本篇来学习Groovy中日期和时间的处理
实例
/*
@Time:2022/8/26
@Author: 大海
*/
Date date = new Date();
println(date.toString());
println(date.getDateString())
println(date.dateTimeString)
// 格式化时间
println(date.format("yyyy-MM-dd HH:mm:ss"))
// after 测试此日期是否在指定日期之后
Date oldDate = new Date("05/11/2015")
Date newDate = new Date("05/12/2022")
Date latestDate = new Date()
println(oldDate.after(newDate))
println(latestDate.after(newDate))
// equals 比较两个日期的相等性。当且仅当参数不为null时,结果为true,并且是表示与该对象时间相同的时间点(毫秒)的Date对象
println(oldDate.equals(newDate))
println(latestDate.equals(newDate))
// 返回自此Date对象表示的1970年1月1日,00:00:00 GMT以来的毫秒数
println(oldDate.getTime())
以上是关于15-Groovy-日期和时间的主要内容,如果未能解决你的问题,请参考以下文章