java和android 的DateFormat的具体格式介绍


//java DateFormat
String help[] = {
"To use this program, enter a time value",
"in the top text field, and a SimpleDateFormat",
"format specifier in the second text field,",
"then click on the Format button. Results",
"appear in the text area at the bottom of",
"the window.",
"",
"The time value must be in seconds since the",
"epoch, midnight 1/1/1970.",
"",
"The format specifier is simply a pattern",
"string; certain letters in the pattern will",
"be replaced by values of time or date, ",
"giving complete control over the formatting.",
"The most useful format codes are:",
"",
"Symbol Meaning Presentation Ex.",
"------ ------- ------------ ----",
"G era designator (Text) AD",
"y year (Number) 1996",
"M month in year (Text) July",
"M month in year (Number) 07",
"d day in month (Number) 10",
"h hour in am/pm (Number) 12",
"H hour in day (Number) 0",
"m minute in hour (Number) 30",
"s second in minute (Number) 55",
"S millisecond (Number) 978",
"E day in week (Text) Tue",
"D day in year (Number) 189",
"a am/pm marker (Text) PM",
"z time zone (Text) PST",
"' quote text (Text) 'at'",
"",
"So, for example this format: h:mm a",
"gives this result: 12:08 PM",
};



//Android DateFormat
This class takes as inputs a format string and a representation of a date/time. The format string controls how the output is generated.

Formatting characters may be repeated in order to get more detailed representations of that field. For instance, the format character 'M' is used to represent the month. Depending on how many times that character is repeated you get a different representation.

For the month of September:
M -> 9
MM -> 09
MMM -> Sep
MMMM -> September

The effects of the duplication vary depending on the nature of the field. See the notes on the individual field formatters for details. For purely numeric fields such as HOUR adding more copies of the designator will zero-pad the value to that number of characters.

For 7 minutes past the hour:
m -> 7
mm -> 07
mmm -> 007
mmmm -> 0007

Examples for April 6, 1970 at 3:23am:
"MM/dd/yy h:mmaa" -> "04/06/70 3:23am"
"MMM dd, yyyy h:mmaa" -> "Apr 6, 1970 3:23am"
"MMMM dd, yyyy h:mmaa" -> "April 6, 1970 3:23am"
"E, MMMM dd, yyyy h:mmaa" -> "Mon, April 6, 1970 3:23am&
"EEEE, MMMM dd, yyyy h:mmaa" -> "Monday, April 6, 1970 3:23am"
"'Noteworthy day: 'M/d/yy" -> "Noteworthy day: 4/6/70"

Summary
Constants
char AM_PM This designator indicates whether the HOUR field is before or after noon.
char CAPITAL_AM_PM This designator indicates whether the HOUR field is before or after noon.
char DATE This designator indicates the day of the month.
char DAY This designator indicates the name of the day of the week.
char HOUR This designator indicates the hour of the day in 12 hour format.
char HOUR_OF_DAY This designator indicates the hour of the day in 24 hour format.
char MINUTE This designator indicates the minute of the hour.
char MONTH This designator indicates the month of the year Examples for September: M -> 9 MM -> 09 MMM -> Sep MMMM -> September
char QUOTE Text in the format string that should be copied verbatim rather that interpreted as formatting codes must be surrounded by the QUOTE character.
char SECONDS This designator indicates the seconds of the minute.
char TIME_ZONE This designator indicates the offset of the timezone from GMT.
char YEAR This designator indicates the year.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值