Service Virtualization

 View Only
  • 1.  Formatted Date using httpNow

    Posted Jul 27, 2016 12:49 AM

    Dear Experts,

     

    I would like to return a formatted date using ca built-in function httpNow(), how to do that?

    For example:  2016-12-31T06:59:59Z

     

    Thanks & Regards,Siswanto



  • 2.  Re: Formatted Date using httpNow
    Best Answer

    Posted Jul 29, 2016 09:22 AM

    I do not believe that httpNow() is going to return zulu time you expect based on the format of the date you used in your question. 

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

    There are likely other ways to do this:

     

    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



  • 3.  Re: Formatted Date using httpNow

    Posted Jan 18, 2017 03:45 PM

    Siswanto,

     

    Did Joel's recommendations answer your question?

     

    Regards,

    Reid