Scripting Example for SystemTime

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
Does any one have an example how to script or retrieve systemtime with JYTHON in SOA Test 4.1?


  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    edited January 2006
    Hey LeapTester,

    from java.lang import *

    def getTime():
       time = System.currentTimeMillis()
       print time
       return time

    That should do it. Good luck testing!
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    edited January 2006
    In one of my testmethod , i have one field(input parameter) set effective date:
    I want to write script for setting effective date which includes format like:2006-01-20T15:16:20.035Z
    Can you please provide me javascript or python example for setting this effective date and also
    manipulating this date with '+' or' '-' some days.

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    To get a date in this format, you can use Java's SimpleDateFormat class and use the Calendar class to mess with the day information:

    from java.util import *
    from java.text import *

    def getTime():
       # Get an instance of the calendar
       calendar = Calendar.getInstance()

       # Set the day in the calendar
       day = calendar.get(Calendar.DAY_OF_WEEK)
       calendar.set(Calendar.DAY_OF_WEEK, day+1)

       # Retreive the date from the calendar
       date = calendar.getTime()

       # Create the date formatter
       myFormat = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
       formatter = SimpleDateFormat(myFormat)

       # Create, print, and return the timestamp
       timestamp = formatter.format(date)
       print timestamp
       return timestamp

    Where I set the day in the calendar you can see that I have incremented it by one. You can include any additional logic to modify the day as you would like. Just FYI: that day number is automatically wrapped so that if you go past the number of days in the month, it will automatically increment (or decrement) the month as well.
  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Dudes you guys rule! Now if you would support Perl as well as Python/Jython that would make me even happier:D.

    thanks again,

Sign In or Register to comment.