aspose file tools*
The moose likes Groovy and the fly likes Current date (mm/dd/yyyy) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Languages » Groovy
Bookmark "Current date (mm/dd/yyyy)" Watch "Current date (mm/dd/yyyy)" New topic
Author

Current date (mm/dd/yyyy)

ted bishop
Greenhorn

Joined: Apr 01, 2011
Posts: 2
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
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
Brian,

Thanks for your reply. I got it to work using your example.

Thanks,
Ted
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 29220
    
135

Brian Mooney wrote: Not sure if there's a more Groovylicious way to do things but there's not much code involved in that.

Actually yes. Groovy provides a wrapper to SimpleDateFormat. It's only one line less than your Java version though.


 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Current date (mm/dd/yyyy)
 
Similar Threads
[log4j] DailyRollingFileAppender
JSTL <fmt:parseDate>
Date Display In MM/dd/yyyy
How to fetch Date Field from excel sheet in Java
Current Date time