Reputation: 507
I have the following code to format the date:
def currentDate = new Date().format('E, dd MMM yyyy')
The format is as I expected, however it is written in the language of my computer. How can I get it to give the date in English? Any help? Thanks!
Upvotes: 0
Views: 12130
Reputation: 187499
If you're doing this in a controller, taglib or GSP, try using the formatDate tag instead.
g.formatDate(date: new Date(), format: 'E, dd MMM yyyy', locale: Locale.ENGLISH)
In a GSP you can also invoke it using this tag syntax:
<g:formatDate date="${new Date()}" format='E, dd MMM yyyy', locale="${Locale.ENGLISH}"/>
Upvotes: 0
Reputation: 3124
If you're running in context of a Controller I would suggest you use
def currentDate = new Date()
def formattedDate = g.formatDate(date:currentDate, format: 'E, dd MMM yyyy')
Upvotes: 6
Reputation: 35961
You can use standard date formatter:
import java.text.*
import java.util.Locale
DateFormat formatter = new SimpleDateFormat('E, dd MMM yyyy', Locale.US)
formatter.format(new Date())
Upvotes: 2