gpt4 book ai didi

grails - 在 Grails 中设置默认的 joda 持续时间/周期格式

转载 作者:行者123 更新时间:2023-12-02 07:17:06 25 4
gpt4 key购买 nike

当使用joda time时使用 Grails,您可以设置默认值 LocalDate像他们所做的那样格式化here 。我想对 Duration 做同样的事情和 Period所以我不必输入类似的内容

durationFormatter.print(exampleObject.myDuration)

每次我想显示持续时间或周期时。我想要调用 Duration/Period 对象的 toString() 方法,并让它以所需的格式打印。

我尝试实现 PeriodFormatter在我的配置文件中,就像他们所做的那样 here ,但无济于事。这是我到目前为止在配置文件中的内容:

jodatime {
format.org.joda.time.LocalDate = "yyyy-MM-dd"
format.org.joda.time.PeriodFormatter = { new format.org.joda.time.PeriodFormatterBuilder()
.appendMonths()
.appendSuffix( " month", " months" )
.appendWeeks()
.appendSuffix( " week", " weeks" )
.appendDays()
.appendSuffix( " day", " days" )
.appendHours()
.appendSuffix( " hour", " hours" )
.toFormatter();
}
}

最佳答案

ISOPeriodFormat

字段

cStandard  

这是默认的句点格式化程序。该字段是私有(private)静态并且没有 setter 。但是您可以使用 java-reflection API 更改此值

  final Field f = ISOPeriodFormat.class.getDeclaredField("cStandard");
f.setAccessible(true);
f.set(null, yourPeriodFormatter);

关于grails - 在 Grails 中设置默认的 joda 持续时间/周期格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12306123/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com