开发者

grails date format in English language

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 Eng开发者_高级运维lish? Any help? Thanks!


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')


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())


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}"/>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜