Android根据系统设置获得对应格式的当前日期字符串
来源:互联网 发布:阿迪达斯清风系列 知乎 编辑:程序博客网 时间:2024/05/22 06:22
由于最近一个App需要多语言,这样就会涉及到不同国家的用户对日期格式的需求不一样,为了让用户使用更舒服,尽量按照用户系统设置的日期格式来在App中显示。
直接上代码
public static String formatDateStampString() { long when = System.currentTimeMillis(); int format_flags = DateUtils.FORMAT_NO_NOON_MIDNIGHT | DateUtils.FORMAT_ABBREV_ALL; | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_SHOW_WEEKDAY; return DateUtils.formatDateTime(AppData.getContext(), when, format_flags); }
输出结果:
英文:Wed, Apr 12中文:4月12日周三
关于format_flags的具体说明大概有一些这些:
FORMAT_SHOW_TIME
FORMAT_SHOW_WEEKDAY
FORMAT_SHOW_YEAR
FORMAT_SHOW_DATE
FORMAT_NO_MONTH_DAY
FORMAT_12HOUR
FORMAT_24HOUR
FORMAT_CAP_AMPM
FORMAT_NO_NOON
FORMAT_CAP_NOON
FORMAT_NO_MIDNIGHT
FORMAT_CAP_MIDNIGHT
FORMAT_UTC
FORMAT_ABBREV_TIME
FORMAT_ABBREV_WEEKDAY
FORMAT_ABBREV_MONTH
FORMAT_ABBREV_ALL
FORMAT_NUMERIC_DATE
官方的英文解释如下:(自行翻译吧)
If FORMAT_SHOW_TIME is set, the time is shown as part of the date range. If the start and end time are the same, then just the start time is shown.
If FORMAT_SHOW_WEEKDAY is set, then the weekday is shown.
If FORMAT_SHOW_YEAR is set, then the year is always shown. If FORMAT_SHOW_YEAR is not set, then the year is shown only if it is different from the current year, or if the start and end dates fall on different years.
Normally the date is shown unless the start and end day are the same. If FORMAT_SHOW_DATE is set, then the date is always shown, even for same day ranges.
If FORMAT_NO_MONTH_DAY is set, then if the date is shown, just the month name will be shown, not the day of the month. For example, “January, 2008” instead of “January 6 - 12, 2008”.
If FORMAT_CAP_AMPM is set and 12-hour time is used, then the “AM” and “PM” are capitalized. You should not use this flag because in some locales these terms cannot be capitalized, and in many others it doesn’t make sense to do so even though it is possible.
If FORMAT_NO_NOON is set and 12-hour time is used, then “12pm” is shown instead of “noon”.
If FORMAT_CAP_NOON is set and 12-hour time is used, then “Noon” is shown instead of “noon”. You should probably not use this flag because in many locales it will not make sense to capitalize the term.
If FORMAT_NO_MIDNIGHT is set and 12-hour time is used, then “12am” is shown instead of “midnight”.
If FORMAT_CAP_MIDNIGHT is set and 12-hour time is used, then “Midnight” is shown instead of “midnight”. You should probably not use this flag because in many locales it will not make sense to capitalize the term.
If FORMAT_12HOUR is set and the time is shown, then the time is shown in the 12-hour time format. You should not normally set this. Instead, let the time format be chosen automatically according to the system settings. If both FORMAT_12HOUR and FORMAT_24HOUR are set, then FORMAT_24HOUR takes precedence.
If FORMAT_24HOUR is set and the time is shown, then the time is shown in the 24-hour time format. You should not normally set this. Instead, let the time format be chosen automatically according to the system settings. If both FORMAT_12HOUR and FORMAT_24HOUR are set, then FORMAT_24HOUR takes precedence.
If FORMAT_UTC is set, then the UTC time zone is used for the start and end milliseconds unless a time zone is specified. If a time zone is specified it will be used regardless of the FORMAT_UTC flag.
If FORMAT_ABBREV_TIME is set and 12-hour time format is used, then the start and end times (if shown) are abbreviated by not showing the minutes if they are zero. For example, instead of “3:00pm” the time would be abbreviated to “3pm”.
If FORMAT_ABBREV_WEEKDAY is set, then the weekday (if shown) is abbreviated to a 3-letter string.
If FORMAT_ABBREV_MONTH is set, then the month (if shown) is abbreviated to a 3-letter string.
If FORMAT_ABBREV_ALL is set, then the weekday and the month (if shown) are abbreviated to 3-letter strings.
If FORMAT_NUMERIC_DATE is set, then the date is shown in numeric format instead of using the name of the month. For example, “12/31/2008” instead of “December 31, 2008”.
- Android根据系统设置获得对应格式的当前日期字符串
- android 根据系统日期格式显示日期
- Java根据当前日期获得这一周的日期
- Java根据当前日期获得这一周的日期
- Java根据当前日期获得这一周的日期
- Java根据当前日期获得这一周的日期
- Java根据当前日期获得这一周的日期
- 根据输入的日期 获得当前日期为周几
- 获得系统当前日期
- android 日期格式处理 ,获取当前系统时间并设置格式为--年--月--日
- java获得系统当前时间三种方式及日期格式之间的相互转化
- 20-获得系统当前时间的字符串格式(字符串处理)
- 根据输入日期,获得当前月的天数
- 根据当前系统时间设置日期(周一至日)
- Android 关于从后台获得时间的字符串转为日期格式再变成字符串
- iOS 获得系统当前日期
- java 根据当前时间获得一周日期
- 根据时间的字符串形式(20031110)获得日期型
- windows下作为应用程序启动apache的方法
- 自定义控件-仿QQ导航栏-跟手指示条
- Java java 程序员 计划表 工作三年以内
- 面向接口编程的好处
- spring mvc controller间跳转 重定向 传参
- Android根据系统设置获得对应格式的当前日期字符串
- docker基础(陆续更新)
- vue-route+webpack部署单页路由项目,访问刷新出现404问题
- Java自带的性能监测工具用法简介——jstack、jconsole、jinfo、jmap、jdb、jsta、jvisualvm
- JavaWeb项目前端学习之CSS background-image的url路径问题
- 判断网络是否可用的方法
- 解决windows安装opencv中,出现问题:error configuration process, project files may be invalid
- Head First SQL 第二章
- Caffe+Ubuntu14.04+CUDA7.5安装笔记