gpt4 book ai didi

java - 使用 java 中的 getDateTimeFormat 从日历获取自定义格式

转载 作者:行者123 更新时间:2023-12-01 15:37:56 25 4
gpt4 key购买 nike

我有一个类扩展了 Calendar 以支持 Jalali 日历。
目前我正在使用它来格式化日期和时间:

com.ibm.icu.text.DateFormat df = cal.getDateTimeFormat(DateFormat.DEFAULT, DateFormat.DEFAULT,new com.ibm.icu.util.ULocale("fa", "IR", ""));

但这给出的日期如下:1390/09/29 17:22:10
但我需要类似:90/09/29 17:22
如何在不使用 SimpleDateFormat 的情况下执行此操作?

谢谢

最佳答案

getDateTimeFormat() 不是 Calendar 中的方法,因此这意味着它是在您使用的任何 Calendar 子类中实现的。我希望以下其中一项能够完成您想要的操作(不过只是猜测!):

com.ibm.icu.text.DateFormat df = cal.getDateTimeFormat(DateFormat.MEDIUM, DateFormat.MEDIUM, new com.ibm.icu.util.ULocale("fa", "IR", ""));
// or
com.ibm.icu.text.DateFormat df = cal.getDateTimeFormat(DateFormat.SHORT, DateFormat.SHORT, new com.ibm.icu.util.ULocale("fa", "IR", ""));

即:尝试传递DateFormat.MEDIUMDateFormat.SHORT而不是DateFormat.DEFAULT .

关于java - 使用 java 中的 getDateTimeFormat 从日历获取自定义格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8580626/

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