lal*_*une 3 groovy datetime monthcalendar
我试着在groovy中获得本月的简称,但是在德语中...(Jan,Feb,Mrz,Apr ......)
我可以用简单的语句用英语得到它:
mydate='2012-11-23 02:26:55.983'
origDate=new Date().parse('yyyy-MM-dd H:mm:ss.S',mydate).format('MMM')
Run Code Online (Sandbox Code Playgroud)
但是用德语?
提前致谢!
使用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'
Run Code Online (Sandbox Code Playgroud)
更长的例子:
def months = new SimpleDateFormat( 'MMM', Locale.GERMANY ).with { sdf ->
(1..12).collect { month ->
sdf.format( Date.parse( 'MM', "$month" ) )
}
}
println months
Run Code Online (Sandbox Code Playgroud)
打印:
[Jan, Feb, Mrz, Apr, Mai, Jun, Jul, Aug, Sep, Okt, Nov, Dez]
Run Code Online (Sandbox Code Playgroud)