I'm trying to get the current date in format mm/dd/yyyy. Using the code below I'm getting the date with a 2 digit year and no leading zeros (4/1/11).
<groovy>
def dateTime = new Date()
def date = dateTime.getDateString()
step.setWebtestProperty('send.date', date)
</groovy>
Thanks,
Ted
Brian Mooney
Greenhorn
Joined: Sep 30, 2010
Posts: 3
posted
0
ted bishop wrote:I'm trying to get the current date in format mm/dd/yyyy. Using the code below I'm getting the date with a 2 digit year and no leading zeros (4/1/11).
<groovy>
def dateTime = new Date()
def date = dateTime.getDateString()
step.setWebtestProperty('send.date', date)
</groovy>
Thanks,
Ted
Hey,
You should be able to use the SimpleDateFormat class from java. Not sure if there's a more Groovylicious way to do things but there's not much code involved in that.
You can read up about the SimpleDateFormat class though its API documentation SimpleDateFormat
Should be as simple as defining you're required date format and then formating the Date object to return the required string.
Amn't familiar with the setWebTestProperty method from the step class?
But the below seems to run ok from the groovy cmd line groovysh.
Prints out as:
04/06/2011
ted bishop
Greenhorn
Joined: Apr 01, 2011
Posts: 2
posted
0
Brian,
Thanks for your reply. I got it to work using your example.