开发者

grails date format in English language

开发者 https://www.devze.com 2023-03-28 14:05 出处:网络
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.

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

精彩评论

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