如何使用groovy在soapui中创建日期时间字符串

发布于 2024-08-29 13:51:30 字数 1436 浏览 3 评论 0原文

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

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

发布评论

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

评论(3

谁对谁错谁最难过 2024-09-05 13:51:30

使用

  1. 插入格式化的时间戳值。在这种情况下使用 SimpleDateFormat:

    ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}

  2. 将时间戳格式设置为 xsd:dateTime 值。使用 DatatypeFactory 创建 newXMLGregorianCalendar 的实例:

    ${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}

我认为第一种情况适合您。在您的请求中插入代码并根据您的需要调整时间戳格式。顺便说一句,它也适用于模拟服务器的响应。

There are two common cases of inserting dynamic dateTime value in soapUI using :

  1. Insert formatted timestamp value. Use SimpleDateFormat in this case:

    ${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ").format(new Date())}

  2. Format timestamp as xsd:dateTime value. Use DatatypeFactory to create instance of newXMLGregorianCalendar:

    ${=javax.xml.datatype.DatatypeFactory.newInstance().newXMLGregorianCalendar(GregorianCalendar.getInstance())}

I think that the first case works for you. Insert the code in your request and adjust timestamp format for your needs. BTW, it also works in responses for mock servers.

深者入戏 2024-09-05 13:51:30

这是一个无需引入 jar 的快速解决方案,可以减轻像 Apache Commons 这样的日期操作的痛苦,或者
joda-time

两行模式比较日期(例如:之前/之后时间):

def startDate = new Date() 
println(startDate.format("yyyy-MM-dd'T'HH:mm:ss SSS"))

或单行模式:

println(new Date().format("yyyy-MM-dd'T'HH:mm:ss SSS"))

如果您工作量大任何繁重的日期操作我都会使用上面的一些 API。我认为 Groovy 还没有开箱即用的高级日期比较功能。

Here's a quick solution without pulling in jars that may ease the pain of Date manipulation like Apache Commons, or
joda-time

Two line mode to compare dates (Ex: before / after times):

def startDate = new Date() 
println(startDate.format("yyyy-MM-dd'T'HH:mm:ss SSS"))

Or one liner mode:

println(new Date().format("yyyy-MM-dd'T'HH:mm:ss SSS"))

If you doing heavy any heavy date manipulation I'd go with some of the above API's. I don't think out of box Groovy has advanced date comparisons yet.

国粹 2024-09-05 13:51:30

注释使用纯 Groovy,其中 SoapUI 不使用 println 等一些常见语法 - 相反,它采用 log.info

today = new Date().format("yyyy-MM-dd")
log.info today

The comments are using pure Groovy which SoapUI doesn't use some of the common syntax like println - instead it takes log.info.

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