我得到一个整数,我需要在当前语言环境中转换为月份名称:

locale en-us 的示例:
1 -> 一月
2 -> 二月

我在 gremlin 中的代码示例:

.....groupBy{[it[3], it[2].getMonth()]}{it[1]}{it.sum()}.cap().scatter().transform{[Name:it.key,Tx:it.value]}

在这里我得到:
==>{Name=[ABC, 7], Tx=1750.0}

我想要名称格式的月份整数。

我试过了 ,
it[2].getMonth().toString() and also as cal.get(Calendar.MONTH) etc 。但没有成功。

最佳答案

要将月份整数转换为字符串,您可以执行以下操作:

String month = new java.text.DateFormatSymbols().months[ 4 ]

assert month == 'May'

关于groovy - 如何在 Groovy 中将整数转换为月份名称?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/18868182/

10-11 22:26
查看更多