public final class Time
extends java.lang.Object
Here is an example of Time being used to display the current date:
Time t = new Time(); ... label.setText("Today is " + t.year + "/" + t.month + "/" + t.day);You can also call the update method to update the time with the current system values.
Modifier and Type | Field and Description |
---|---|
int |
day
The day in the range of 1 to the last day in the month.
|
int |
hour
The hour in the range of 0 to 23.
|
int |
millis
Milliseconds in the range of 0 to 999.
|
int |
minute
The minute in the range of 0 to 59.
|
int |
month
The month in the range of 1 to 12.
|
int |
second
The second in the range of 0 to 59.
|
static int |
SECONDS_PER_DAY |
int |
year
The year as its full set of digits (year 2010 is 2010).
|
Constructor and Description |
---|
Time()
Constructs a time object set to the current date and time.
|
Time(char[] sqlTime)
Creates a Time object from an SQL String.
|
Time(Date d)
Constructs a time object from a Date, zeroing the hour/minute/second and millis
|
Time(int yyyymmdd,
int hhmmssmmm)
Constructs a time object from the given date and time values.
|
Time(int year,
int month,
int day,
int hour,
int minute,
int second,
int millis)
Constructs a new time with the given values.
|
Time(long yyyymmddhhmmss)
Constructs a time object from the given value.
|
Time(long time,
boolean b)
Creates a time in the SQL' format.
|
Time(java.lang.String iso8601)
Creates a Time object with a String in the given Iso8601 format:
|
Time(java.lang.String time,
boolean hasYear,
boolean hasMonth,
boolean hasDay,
boolean hasHour,
boolean hasMinute,
boolean hasSeconds)
Constructs a Time object, parsing the String and placing the fields depending on
the flags that were set, using the Settings.timeSeparator as spliter.
|
Time(java.lang.String time,
boolean hasYear,
boolean hasMonth,
boolean hasDay,
boolean hasHour,
boolean hasMinute,
boolean hasSeconds,
byte dateFormat)
Constructs a Time object, parsing the String and placing the fields depending on
the flags that were set, using the Settings.timeSeparator as spliter.
|
Modifier and Type | Method and Description |
---|---|
java.lang.StringBuffer |
dump(java.lang.StringBuffer sb,
java.lang.String timeSeparator,
boolean includeMillis)
Dumps the time into the given StringBuffer.
|
boolean |
equals(java.lang.Object o) |
long |
getSQLLong()
Returns the time in the format YYYYMMDDHHmmSSmmm as a long value.
|
java.lang.String |
getSQLString()
Returns this date in the format
YYYY-MM-DD HH:mm:SS.mmm |
java.lang.String |
getSQLString(java.lang.StringBuffer sb)
Returns this date in the format
YYYY-MM-DD HH:mm:SS.mmm |
long |
getTime()
Returns the number of millis since 1/1/1970
|
long |
getTimeLong()
Returns the time in the format YYYYMMDDHHMMSS as a long value.
|
void |
inc(int hours,
int minutes,
int seconds)
Increments or decrements the fields below.
|
boolean |
isValid()
Returns true if the time is valid.
|
java.lang.String |
toIso8601()
Converts this time object to a string in the Iso8601 format:
|
java.lang.String |
toString()
Returns the time in format specified in totalcross.sys.Settings (does NOT include the date neither the millis).
|
java.lang.String |
toString(java.lang.String timeSeparator)
Returns the time in format specified in totalcross.sys.Settings (does NOT include the date neither the millis).
|
void |
update()
Updates the internal fields with the current timestamp.
|
public int year
public int month
public int day
public int hour
public int minute
public int second
public int millis
public static final int SECONDS_PER_DAY
public Time()
public Time(Date d)
public Time(long yyyymmddhhmmss)
getTimeLong()
public Time(int yyyymmdd, int hhmmssmmm)
public Time(java.lang.String iso8601) throws InvalidNumberException
YYYYMMDDTHH:MM:SS.
InvalidNumberException
public Time(char[] sqlTime) throws InvalidDateException
InvalidDateException
public Time(long time, boolean b) throws InvalidDateException
time
- Number of millis since 1/1/1970b
- Here only to differ from the other constructor that receives a long and its ignored.InvalidDateException
public Time(java.lang.String time, boolean hasYear, boolean hasMonth, boolean hasDay, boolean hasHour, boolean hasMinute, boolean hasSeconds) throws InvalidNumberException
InvalidNumberException
public Time(java.lang.String time, boolean hasYear, boolean hasMonth, boolean hasDay, boolean hasHour, boolean hasMinute, boolean hasSeconds, byte dateFormat) throws InvalidNumberException
InvalidNumberException
public Time(int year, int month, int day, int hour, int minute, int second, int millis)
public void update()
public long getTime() throws InvalidDateException
InvalidDateException
public long getTimeLong()
public long getSQLLong()
public java.lang.String getSQLString()
YYYY-MM-DD HH:mm:SS.mmm
public java.lang.String getSQLString(java.lang.StringBuffer sb)
YYYY-MM-DD HH:mm:SS.mmm
public java.lang.String toString()
Time t = new Time(); String dateAndTime = new Date(t) + " " + t;
toString
in class java.lang.Object
public java.lang.String toString(java.lang.String timeSeparator)
Time t = new Time(); String dateAndTime = new Date(t) + " " + t;
public java.lang.StringBuffer dump(java.lang.StringBuffer sb, java.lang.String timeSeparator, boolean includeMillis)
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public java.lang.String toIso8601()
YYYYMMDDTHH:MM:SS.
public boolean isValid()
public void inc(int hours, int minutes, int seconds)