Groovy:日期没有正确计算?使用TimeCategory

时间:2010-11-20 04:18:42

标签: groovy soapui

任何人都可以告诉我为什么没有正确计算这些。我正在尝试添加1秒的时间,当我应用格式时,它似乎增加了60毫秒?

    import java.text.*
    import java.util.*
    import groovy.time.TimeCategory

    def xmlSlurper = new groovy.util.XmlSlurper()  

    // Get the previous total for number of journals
    def journalCountProp = testRunner.testCase.getTestStepByName("Properties")
    def journalCountTotal = journalCountProp.getPropertyValue( "journalCount" )
    log.info " 1. Previous JournalCount from last run: "+journalCountTotal

    def lastDateProp = testRunner.testCase.getTestStepByName("Properties")
    def lastDateHolder = lastDateProp.getPropertyValue( "journalQueryDate" )
    log.info " 2. Previous lastDate from last run: "+lastDateHolder 

    // Get the response for a given timeline
    def response = xmlSlurper.parseText(context.expand('${GET Journal using JournalDate#Response}'));
    def currentJournalCount = response.Journals.Journal.size()
    log.info " 3. Number of Journals in this Run: "+currentJournalCount

    //Getting the date from the last Journal (including an offset as the array count starts at 0)
    def lastDate = response.Journals.Journal[currentJournalCount-1].CreatedDateUTC
    log.info " 4. CreatedDate from last journal in this response: "+lastDate

    //log.info response.Journals.Journal[currentJournalCount-1].CreatedDateUTC

    def newdate = Date.parse("yyyy-MM-dd'T'HH:mm:ss.mmm",lastDate.toString())
    log.info "dateBeforeChange: "+newdate.format("yyyy-MM-dd'T'HH:mm:ss.mmm")
    use(TimeCategory){
     newdate = newdate+1.seconds
    }

    log.info "date After Change: "+newdate.format("yyyy-MM-dd'T'hh:mm:ss.mmm")
    log.info " 5. "+newdate.format("yyyy-MM-dd'T'HH:ss:mmm")

输出:

此回复中上一期刊的CreatedDate:2007-03-29T23:19:52.073
dateBeforeChange:2007-03-30T00:13:52.013
更改日期:2007-03-30T12:13:53.013

我无法理解?!!

干杯, - 理查德

1 个答案:

答案 0 :(得分:0)

HH表示“一天中的小时(0-23)”,而hh表示“上午/下午(1-12)”。 请参阅SimpleDateFormat ApiDoc以获取参考资料(引擎盖下使用SimpleDateFormat)。