`
zhy20045923
  • 浏览: 155813 次
  • 性别: Icon_minigender_1
  • 来自: 深圳
社区版块
存档分类
最新评论

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. 
分享到:
评论

相关推荐

    Java/Android 获取系统时间

    ### Java/Android 获取系统时间 #### 一、Java获取系统时间的方法 在Java中,有多种方式可以获取当前系统的日期和时间。...通过合理的使用这些类及其提供的方法,我们可以轻松地完成获取和格式化系统时间的任务。

    date_java_android_

    8. **国际化(i18n)**:除了语言,地区选择还可能涉及到时间格式、日期格式的国际化,开发者需要了解Android的区域设置(Locale)和时间日期格式化类(DateFormat、SimpleDateFormat)。 9. **UI动画**:为了提升...

    java 手机时间显示

    在Java SE(标准版)中,我们通常使用`java.util.Date`类和`java.text.SimpleDateFormat`类来获取和格式化日期和时间。首先,我们可以创建一个`Date`对象来获取当前系统时间: ```java import java.util.Date; ...

    Android日期时间格式国际化的实现代码

    总之,Android中的日期时间格式国际化主要是通过`java.text.DateFormat`类及其子类来实现的,结合`Locale`对象,可以轻松地根据用户的语言和地区设置来展示日期和时间。在实际应用中,还可以结合资源文件(strings....

    android 系统时间 完整版

    本文将详细介绍如何使用Android提供的API以及Java标准库中的类来获取和格式化系统当前时间,并以示例代码的方式展示如何实现这一功能。 首先,获取系统当前时间可以通过使用`java.util.Date`类来实现。`Date`类提供...

    android国际化

    2. 数字和日期格式:Android提供java.text包,包含NumberFormat和DateFormat类,用于处理不同地区的数字和日期格式。开发者可以根据用户设备的语言设置自动调整这些格式。 3. 图片和布局适配:对于不同屏幕尺寸和...

    Android 学习资料

    8. **Android 系统日期时间获取**:这部分会介绍如何使用Java的Date和Calendar类,以及Android特有的日期时间API(如DateFormat和DateUtils)来获取、格式化和处理系统日期和时间。 9. **Android message机制**:...

    Android开发实现保存图片到手机相册功能

    本文将详细介绍Android开发实现保存图片到手机相册功能的实现方法和相关知识点。 一、图片格式的选择 在Android开发中,图片格式的选择非常重要。通常情况下,JPEG格式的图片可以被手机相册识别和显示。但是,其他...

    学习安卓开发的java基础

    - `DateFormat`类:用于格式化和解析日期字符串。 - `Calendar`类:提供更高级的日期和时间操作功能。 #### 10. 数据库连接与操作 - JDBC(Java Database Connectivity):是一种用于执行SQL语句的标准Java API。 -...

    android 时间和日期的设置

    本文将基于提供的文件信息,深入解析如何在Android应用中实现时间和日期的设置,包括使用DatePickerDialog和TimePickerDialog控件的具体步骤。 ### 一、DatePickerDialog - 日期设置控件 #### 1.1 布局文件(main....

    Android应用程序源代码TodayDate

    Android也提供了`android.text.format.DateFormat`和`java.text.SimpleDateFormat`来格式化日期字符串。 5. **获取和显示日期**: - 在`TodayDateActivity`的`onCreate`方法中,开发者会获取当前日期,并将其转换...

    android DeskClock 时钟闹钟源码

    - 使用 `DateFormat` 和 `SimpleDateFormat` 进行日期和时间格式化,展示在界面上。 - `TimePickerDialog` 用于用户选择时间,提供直观的交互方式。 6. **权限管理**: - DeskClock 需要 `WAKE_LOCK` 权限来保证...

    Android静默安装常用工具类

    1、HttpUtils ...static HttpResponse httpGet...getTime(long timeInMillis, SimpleDateFormat dateFormat) 将long转换为固定格式时间字符串 源码可见TimeUtils.java,更多方法及更详细参数介绍可见TimeUtils Api Guide。

    安卓Android源码——桌面显示今天日期源码.zip

    本压缩包文件“安卓Android源码——桌面显示今天日期源码.zip”包含了实现这一功能的具体源代码,以及相关的说明文档。下面,我们将详细探讨如何在Android中实现桌面显示今天日期的功能。 首先,我们要了解Android...

    学习安卓所需要的java知识点

    - **日期相关类**:如`Date`, `DateFormat`, `Calendar`等,用于处理日期和时间。 #### 十六、数据库 - **关系型数据库的基本概念**:一种存储和管理数据的方式,使用表格形式组织数据。 - **SQL分类**:SQL...

    android gosn 使用示例

    在Android开发中,有时我们需要处理JSON数据,包括序列化和反序列化。`gosn`是一个针对Android平台的轻量级库,它提供了方便的JSON操作功能,包括将Java对象转换为JSON字符串以及将JSON字符串解析成Java对象。这篇...

    DateFormat.java

    根据传入的时间与当前时间计算出两个时间的:天,小时,分钟等。

    Java万年历源代码,可显示公历、农历、系统时间、国际时间

    2. Java 日期和时间处理:该代码使用 Java 的日期和时间处理类库,包括 `Calendar`、`Date`、`DateFormat`、`SimpleDateFormat` 等,来处理日期和时间的计算和显示。了解如何使用 Java 的日期和时间处理类库来计算和...

Global site tag (gtag.js) - Google Analytics