欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 文旅 > 明星 > Hutool 获取中文日期

Hutool 获取中文日期

2025/9/6 16:07:40 来源:https://blog.csdn.net/qq_37770674/article/details/140163327  浏览:    关键词:Hutool 获取中文日期

在开发过程中,有时会需要获取全中文格式的日期,比如:二〇二四年七月三日
此时就需要将日期转换成该格式,Hutool 封装了该工具:

/*** 格式化为中文日期格式,如果isUppercase为false,则返回类似:2018年10月24日,否则返回二〇一八年十月二十四日** @param date        被格式化的日期* @param isUppercase 是否采用大写形式* @param withTime    是否包含时间部分* @return 中文日期字符串* @since 5.3.9*/
public static String formatChineseDate(Date date, boolean isUppercase, boolean withTime) {if (null == date) {return null;}if (false == isUppercase) {return (withTime ? DatePattern.CHINESE_DATE_TIME_FORMAT : DatePattern.CHINESE_DATE_FORMAT).format(date);}return CalendarUtil.formatChineseDate(CalendarUtil.calendar(date), withTime);
}

进行如下调用即可得到中文日期:

DateUtil.formatChineseDate(DateUtil.parseDate("2024-07-03"), true, false);

输出结果为:二〇二四年七月三日

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

热搜词