android.text.format.Time时间类

益麻雀
2023-12-01

java.lang.Object

   ↳android.text.format.Time

 

Class Overview(概述)

The Time class is a faster replacement for the java.util.Calendar and java.util.GregorianCalendar classes. An instance of the Time class represents a moment in time, specified with second precision. It is modelled after struct tm, and in fact, uses struct tm to implement most of the functionality.

Time类很快就会取代java.util.Calendar类和java.util.GregorianCalendar类,Time类的一个实例代表一个以秒为精确度的时间。它是仿照结构TM,而事实上,使用struct以旧换新实施的大部分功能。

 

Summary(摘要)

Constants(常量)

 

int     EPOCH_JULIAN_DAY     The Julian day of the epoch, that is, January 1, 1970 on the Gregorian calendar.
int     FRIDAY     
int     HOUR     
int     MINUTE     
int     MONDAY     
int     MONDAY_BEFORE_JULIAN_EPOCH     The Julian day of the Monday in the week of the epoch, December 29, 1969 on the Gregorian calendar.
int     MONTH     
int     MONTH_DAY     
int     SATURDAY     
int     SECOND     
int     SUNDAY     
int     THURSDAY     
String     TIMEZONE_UTC     
int     TUESDAY     
int     WEDNESDAY     
int     WEEK_DAY     
int     WEEK_NUM     
int     YEAR

 

int     YEAR_DAY    

 

Fields

public boolean     allDay     True if this is an allDay event.

public long     gmtoff     Offset from UTC (in seconds).

public int     hour     Hour of day [0-23]

public int     isDst     This time is in daylight savings time.

public int     minute     Minute [0-59]

public int     month     Month [0-11]

public int     monthDay     Day of month [1-31]

public int     second     Seconds [0-61] (2 leap seconds allowed)

public String     timezone     The timezone for this Time.

public int     weekDay     Day of week [0-6]

public int     year     Year.

public int     yearDay     Day of year [0-365]

 

 

Public Constructors(公共构造器)
    Time(String timezone)
Construct a Time object in the timezone named by the string argument "timezone".
    Time()
Construct a Time object in the default timezone.
    Time(Time other)

 

A copy constructor.

 

Public Methods(公共函数)

 

boolean     after(Time that)

 

Returns true if the time represented by this Time object occurs after the given time.

与给定的时间比较,如果比给定的时间晚则返回true,否则返回false。

 

boolean     before(Time that)

Returns true if the time represented by this Time object occurs before the given time.

这个跟after函数实现的功能可以说一样,只是这样定义名字就可以更符合设计逻辑。

 

void     clear(String timezone)

Clears all values, setting the timezone to the given timezone.

清空所有变量值,并把时区设置为给定时区。

 

static int     compare(Time a, Time b)

return a negative number if a is less than b, a positive number if a is greater than b, and 0 if they are equal.

如果a比b小则返回一个负数,如果a比b大则返回一个正数,如果相等则返回0。

 

String     format(String format)

Print the current value given the format string provided.

转换成给定格式的字符串。

 

String     format2445()

Format according to RFC 2445 DATETIME type.

转换成RFC 2445 格式的字符串。如:20121211155343

就跟这样调用format函数一样,format("%Y%m%dT%H%M%S") 。

 

String     format3339(boolean allDay)

Return a string in the RFC 3339 format.

转换成RFC 3339格式的字符串。

如:allDay是true,2012-12-11;allDay是false,2012-12-11T15:53:43.000+08:00

 

int     getActualMaximum(int field)

Return the maximum possible value for the given field given the value of the other fields.

 

static String     getCurrentTimezone()

Returns the timezone string that is currently set for the device.

返回当前设备中设置的时区字符串。

 

static int     getJulianDay(long millis, long gmtoff)

Computes the Julian day number, given the UTC milliseconds and the offset (in seconds) from UTC.

 

static int     getJulianMondayFromWeeksSinceEpoch(int week)

Takes a number of weeks since the epoch and calculates the Julian day of the Monday for that week.

 

int     getWeekNumber()

Computes the week number according to ISO 8601.

 

static int     getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek)

Returns the week since EPOCH_JULIAN_DAY (Jan 1, 1970) adjusted for first day of week.

 

static boolean     isEpoch(Time time)

Returns true if the day of the given time is the epoch on the Julian Calendar (January 1, 1970 on the Gregorian calendar).

 

long     normalize(boolean ignoreDst)

Ensures the values in each field are in range.

规范化,保证每一个field值没有超出最大值。

 

boolean     parse(String s)

Parses a date-time string in either the RFC 2445 format or an abbreviated format that does not include the "time" field.

解析一个RFC 2445格式或者一个缩写格式的时间。

 

boolean     parse3339(String s)

Parse a time in RFC 3339 format.

解析一个RFC 3339格式的时间。

 

void     set(int second, int minute, int hour, int monthDay, int month, int year)

Sets the fields.

void     set(int monthDay, int month, int year)

Sets the date from the given fields.

void     set(Time that)

Copy the value of that to this Time object.

void     set(long millis)

Sets the fields in this Time object given the UTC milliseconds.

long     setJulianDay(int julianDay)

Sets the time from the given Julian day number, which must be based on the same timezone that is set in this Time object.

设置时间类中的时间。

 

void     setToNow()

Sets the time of the given Time object to the current time.

设置时间类中的时间为系统当前时间,即可以获得当前时间。

 

void     switchTimezone(String timezone)

Convert this time object so the time represented remains the same, but is instead located in a different timezone.

设置时间类中的时区信息,时间会随着时区的变化而变化。

如:原来时区是中国北京GTM+8:00,时间是13:00,现在设置为英国伦敦格林威治标准时间GTM,那么时间应该变成5:00 。

 

long     toMillis(boolean ignoreDst)

Converts this time to milliseconds.

转换时间成秒。

 

String     toString()

Return the current time in YYYYMMDDTHHMMSS format

转换成字符串,返回YYYYMMDDTHHMMSS格式的时间字符串。

 

[Expand]
Inherited Methods(继承函数)
From class java.lang.Object

 类似资料: