使用 DateFormat,即我可以将当前日期格式化为短本地化日期,如下所示:
It is quite easy to format and parse Java Date (or Calendar) classes using instance of DateFormat, i.e. I could format current date into short localize date like this:
DateFormat formatter = DateFormat.getDateInstance(DateFormat.SHORT, Locale.getDefault());
String today = formatter.format(new Date());
我的问题是:我需要获取这个本地化的模式字符串(即像 "MM/dd/yy" 之类的东西).这应该是一项微不足道的任务,但我就是找不到提供者...
My problem is: I need to obtain this localized pattern string (i.e. something like "MM/dd/yy"). This should be a trivial task, but I just couldn't find the provider...
For SimpleDateFormat,你调用 toLocalizedPattern()
对于 Java 8 用户:
For Java 8 users:
Java 8 日期时间 API 类似于 Joda-time.为了获得本地化模式,我们可以使用类DateTimeFormatter
The Java 8 Date Time API is similar to Joda-time. To gain a localized pattern we can use class DateTimeFormatter
DateTimeFormatter.ofLocalizedDate(FormatStyle.MEDIUM);
请注意,当您在 LocalDate 上调用 toString() 时,您将获得 ISO-8601 格式的日期
Note that when you call toString() on LocalDate, you will get date in format ISO-8601
请注意,Java 8 中的日期时间 API 受到 Joda Time 的启发,大多数解决方案都可以基于与时间相关的问题.
Note that Date Time API in Java 8 is inspired by Joda Time and most solution can be based on questions related to time.
这篇关于如何获取本地化的日期模式字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
上传进度侦听器未触发(Google 驱动器 API)Upload progress listener not fired (Google drive API)(上传进度侦听器未触发(Google 驱动器 API))
使用 Google Drive SDK 将文件保存在特定文件夹中Save file in specific folder with Google Drive SDK(使用 Google Drive SDK 将文件保存在特定文件夹中)
Google Drive Android API - 无效的 DriveId 和 Null ResourcGoogle Drive Android API - Invalid DriveId and Null ResourceId(Google Drive Android API - 无效的 DriveId 和 Null ResourceId)
谷歌驱动api服务账户查看上传文件到谷歌驱动使Google drive api services account view uploaded files to google drive using java(谷歌驱动api服务账户查看上传文件到谷歌驱动使用java
Google Drive 服务帐号返回 403 usageLimitsGoogle Drive service account returns 403 usageLimits(Google Drive 服务帐号返回 403 usageLimits)
com.google.api.client.json.jackson.JacksonFactory;Google Drcom.google.api.client.json.jackson.JacksonFactory; missing in Google Drive example(com.google.api.client.json.jackson.JacksonFactory;Google Drive 示例