Incrementing date object by hours/minutes in Groovy

后端 未结 1 551
难免孤独
难免孤独 2020-12-15 03:09

I want to add hours or minutes to a current date. For example I create a Date object with current time and date, and I want to increment it by 30min, how can I do such thing

相关标签:
1条回答
  • 2020-12-15 03:56

    You can use TimeCategory

    import groovy.time.TimeCategory
    
    currentDate =  new Date()
    
    println currentDate
    
    use( TimeCategory ) {
        after30Mins = currentDate + 30.minutes
    }
    
    println after30Mins
    
    0 讨论(0)
提交回复
热议问题