Format Date using httpNow
search cancel

Format Date using httpNow

book

Article ID: 451031

calendar_today

Updated On:

Products

Service Virtualization

Issue/Introduction

We need us to update the http response header time zone to GMT; it is currently set to CDT where the server is located. 

We do not want to update the DevTest default date time setting, just the value for this one virtual  service.


The field in the VSI file that controls this value.is Date {{=httpNow()}

Is there a list of alternate variables that I can put in this field to alter the response value.    (Yes they do need a dynamic response time stamp)

Environment

All supported DevTest releases.

Resolution

Following are a couple of different approaches using various date formats and techniques.  Only the last approach provides a Zulu date/time. 

 

1) Using a JSR-223 step and sending in httpNow provided this resulting date/time:

String s = "{{=httpNow()}}";

String dt = testExec.parseInState( s );  

testExec.setStateValue("fl_date", dt );

// value of fl_date = FRI, 29 Jul 2016 08:05:29 CDT

 

2) Using the OOTB date time Filter found under Filters / Utility option:

// Use Filter Date Pattern = yyyy-MM-dd'T'HH:mm:ss'Z'

// Converted value       =     2016-07-29T08:05:29Z

 

// Use Filter Date Pattern = yyyy-MM-dd'T'HH:mm:ssZ

// Use Filter Date Pattern = 2016-07-29T08:05:29-0500

 

3) Using JSR-223 and SimpleDate format to get a Zulu representation

// I suppose you could run httpNow() through this logic so long as you change the SimpleDateFormat to accept accordingly

import java.util.Date;

import java.text.SimpleDateFormat;

 

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");

sdf.setTimeZone(TimeZone.getTimeZone("GMT"));

Date now = new Date();

String zuluDate = sdf.format(now);

testExec.setStateValue("fl_zuluDate", zuluDate);

// value of fl_zuluDate is:  2016-07-29T13:05:29Z

Additional Information

Communities Post:

Formatted Date using httpNow