Android工具類1-Timejava
public classandroid
java.lang.Object | |
↳ | android.text.format.Time |
An alternative to the Calendar
and 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.less
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] |
boolean | after(Time that)
Returns true if the time represented by this Time object occurs after the given time.
|
boolean | before(Time that)
Returns true if the time represented by this Time object occurs before the given time.
|
static int | compare(Time a, Time b)
Compare two
Time objects and return a negative number if
a is less than
b , a positive number if
a is greater than
b , or 0 if they are equal.
|
String | format2445()
Format according to RFC 2445 DATETIME type.
|
String | format3339(boolean allDay)
Return a string in the RFC 3339 format.
|
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 | getJulianMondayFromWeeksSinceEpoch(int week) Added in API level 11
Takes a number of weeks since the epoch and calculates the Julian day of the Monday for that week.
|
static int | getWeeksSinceEpochFromJulianDay(int julianDay, int firstDayOfWeek)
Returns the week since
EPOCH_JULIAN_DAY (Jan 1, 1970) adjusted for first day of week.
|
int | getWeekNumber()
Computes the week number according to ISO 8601.
|
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.
|
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.
|
Time time =newTime();
String date ="20081013T160000Z";
time.parse(date);
long millis = time.normalize(false);
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(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.
|
long | toMillis(boolean ignoreDst)
Converts this time to milliseconds.
|
Time time =newTime();
time.set(4,10,2007);// set the date to Nov 4, 2007, 12am
time.normalize();// this sets isDst = 1
time.monthDay +=1;// changes the date to Nov 5, 2007, 12am
millis = time.toMillis(false);// millis is Nov 4, 2007, 11pm
millis = time.toMillis(true);// millis is Nov 5, 2007, 12am