I try to get the short name of the month in groovy, but in German... (Jan, Feb, Mrz, Apr...)
I can get it in English with the simple statement:
mydate='2012-11-23 02:26:55.983'
origDate=new Date().parse('yyyy-MM-dd H:mm:ss.S',mydate).format('MMM')
but in german ?
thanks in advance!
Use SimpleDateFormat:
import java.text.SimpleDateFormat
String mydate = '2012-03-23 02:26:55.983'
SimpleDateFormat sdf = new SimpleDateFormat( 'MMM', Locale.GERMANY )
assert sdf.format( Date.parse( 'yyyy-MM-dd H:mm:ss.S', mydate ) ) == 'Mrz'
Longer example:
def months = new SimpleDateFormat( 'MMM', Locale.GERMANY ).with { sdf ->
(1..12).collect { month ->
sdf.format( Date.parse( 'MM', "$month" ) )
}
}
println months
prints:
[Jan, Feb, Mrz, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]