Groovy:日期计算不正确?使用时间类别

发布于 2024-10-03 03:05:39 字数 1884 浏览 2 评论 0原文

谁能告诉我为什么这些计算不正确。我试图增加 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
更改前日期:2007-03-30T00:13:52.013
更改后的日期:2007-03-30T12:13:53.013

我不明白?!!

干杯, ——理查德

can anyone tell me why these aren't being calculated correctly. I'm trying to add 1 second to the time and it seems to be adding 60 milliseconds when I apply formatting?

    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")

OUTPUT:

CreatedDate from last journal in this response: 2007-03-29T23:19:52.073
dateBeforeChange: 2007-03-30T00:13:52.013
date After Change: 2007-03-30T12:13:53.013

I can't figure it out?!!

Cheers,
- Richard

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

昔梦 2024-10-10 03:05:39

HH 表示“一天中的小时 (0-23)”,而 hh 表示“上午/下午的小时 (1-12)”。
请参阅 SimpleDateFormat ApiDoc 供参考(SimpleDateFormat 在幕后使用)。

HH means "hour in a day (0-23)", whereas hh means "hour in am/pm (1-12)".
See the SimpleDateFormat ApiDoc for a reference (SimpleDateFormat is used under the hood).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文