Forum Discussion

Dee1978's avatar
Dee1978
New Member
4 years ago

SOAP UI - how to pass Current date time json in UTC format and RFC 7231 format in the header

I am using SOAP UI and submitting a JSON submission. However I am not sure how to submit so that the current date/time is automatically populated like for the JSON body field as below
"receivedDateTime":"2020-09-10T07:40:00.001Z"
I tried the following for a similar field as above
"preparationDateTime":"${=new java.text.SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'").format(new java.util.Date())}", but I don't think it works

 

HEADER
I have been able to set up the current UTC format for one of the dates in the header but that's UTC format
${= new Date().format("yyyy-MM-dd'T'HH:mm:ss.SSSZ") }
but another date in the header date/time needs to be in RFC7231 format - Thu, 01 Oct 2020 13:30:23 GMT so not sure how to do this?
Can anyone help please?

1 Reply

  • richie's avatar
    richie
    Community Hero

    Hey Dee1978 

     

    I was a bit confused by your post - do I understand correctly - you want an inline scripting option to generate the current date time (including timezone indicator using the format corresponding to 'Thu, 01 Oct 2020 13:30:23 GMT'. 

     

    Is that correct?

     

    The following:

    ${=import java.text.SimpleDateFormat; Calendar cal = Calendar.getInstance(); cal.add(Calendar.DATE, -0); new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z").format(cal.getTime());}

     

    when executed generated the following in my request's payload:

    "dateAttribute" : "Thu, 08 Oct 2020 00:43:03 BST"

     

    I'm currently running this in the UK, and it's currently british summer time, hence the timezone ('z' flag) generated 'BST' in the value.  Once the clocks change 'BST' will be replaced by either 'GMT' or 'UTC' (although I dont know which)

     

     

    Does that answer all your question?

     

    Cheers,

     

    rich