Package totalcross.sys
Class Time
- java.lang.Object
-
- totalcross.sys.Time
-
public final class Time extends java.lang.ObjectTime identifies a date and time.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.
-
-
Field Summary
Fields Modifier and Type Field Description intdayThe day in the range of 1 to the last day in the month.inthourThe hour in the range of 0 to 23.intmillisMilliseconds in the range of 0 to 999.intminuteThe minute in the range of 0 to 59.intmonthThe month in the range of 1 to 12.intsecondThe second in the range of 0 to 59.static intSECONDS_PER_DAYintyearThe year as its full set of digits (year 2010 is 2010).
-
Constructor Summary
Constructors Constructor 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(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.Time(Date d)Constructs a time object from a Date, zeroing the hour/minute/second and millis
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringBufferdump(java.lang.StringBuffer sb, java.lang.String timeSeparator, boolean includeMillis)Dumps the time into the given StringBuffer.booleanequals(java.lang.Object o)longgetSQLLong()Returns the time in the format YYYYMMDDHHmmSSmmm as a long value.java.lang.StringgetSQLString()Returns this date in the formatYYYY-MM-DD HH:mm:SS.mmmjava.lang.StringgetSQLString(java.lang.StringBuffer sb)Returns this date in the formatYYYY-MM-DD HH:mm:SS.mmmlonggetTime()Returns the number of millis since 1/1/1970longgetTimeLong()Returns the time in the format YYYYMMDDHHMMSS as a long value.voidinc(int hours, int minutes, int seconds)Increments or decrements the fields below.booleanisValid()Returns true if the time is valid.java.lang.StringtoIso8601()Converts this time object to a string in the Iso8601 format:java.lang.StringtoString()Returns the time in format specified in totalcross.sys.Settings (does NOT include the date neither the millis).java.lang.StringtoString(java.lang.String timeSeparator)Returns the time in format specified in totalcross.sys.Settings (does NOT include the date neither the millis).voidupdate()Updates the internal fields with the current timestamp.
-
-
-
Field Detail
-
year
public int year
The year as its full set of digits (year 2010 is 2010).
-
month
public int month
The month in the range of 1 to 12.
-
day
public int day
The day in the range of 1 to the last day in the month.
-
hour
public int hour
The hour in the range of 0 to 23.
-
minute
public int minute
The minute in the range of 0 to 59.
-
second
public int second
The second in the range of 0 to 59.
-
millis
public int millis
Milliseconds in the range of 0 to 999.
-
SECONDS_PER_DAY
public static final int SECONDS_PER_DAY
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Time
public Time()
Constructs a time object set to the current date and time.
-
Time
public Time(Date d)
Constructs a time object from a Date, zeroing the hour/minute/second and millis- Since:
- TotalCross 2.0
-
Time
public Time(long yyyymmddhhmmss)
Constructs a time object from the given value.- Since:
- SuperWaba 4.0
- See Also:
getTimeLong()
-
Time
public Time(int yyyymmdd, int hhmmssmmm)Constructs a time object from the given date and time values.- Since:
- TotalCross 1.0 beta 4
-
Time
public Time(java.lang.String iso8601) throws InvalidNumberExceptionCreates a Time object with a String in the given Iso8601 format:YYYYMMDDTHH:MM:SS
.- Throws:
InvalidNumberException- Since:
- SuperWaba 5.61
-
Time
public Time(char[] sqlTime) throws InvalidDateExceptionCreates a Time object from an SQL String. It accepts any character as separator and also with less fields, based that the sequence is always YY-MM-DD hh:mm:ss.mmm.- Throws:
InvalidDateException- Since:
- TotalCross 3.1
-
Time
public Time(long time, boolean b) throws InvalidDateExceptionCreates a time in the SQL' format.- Parameters:
time- Number of millis since 1/1/1970b- Here only to differ from the other constructor that receives a long and its ignored.- Throws:
InvalidDateException- Since:
- TotalCross 2.1
-
Time
public Time(java.lang.String time, boolean hasYear, boolean hasMonth, boolean hasDay, boolean hasHour, boolean hasMinute, boolean hasSeconds) throws InvalidNumberExceptionConstructs a Time object, parsing the String and placing the fields depending on the flags that were set, using the Settings.timeSeparator as spliter. The number of parts must match the number of true flags, or an ArrayIndexOutOfBoundsException will be thrown. AM/PM is supported.- Throws:
InvalidNumberException- Since:
- TotalCross 1.3
-
Time
public Time(java.lang.String time, boolean hasYear, boolean hasMonth, boolean hasDay, boolean hasHour, boolean hasMinute, boolean hasSeconds, byte dateFormat) throws InvalidNumberExceptionConstructs a Time object, parsing the String and placing the fields depending on the flags that were set, using the Settings.timeSeparator as spliter. The number of parts must match the number of true flags, or an ArrayIndexOutOfBoundsException will be thrown. The dateFormat is only considered if hasYear, hasMonth and hasDay are all true. AM/PM is supported.- Throws:
InvalidNumberException- Since:
- TotalCross 2.1
-
Time
public Time(int year, int month, int day, int hour, int minute, int second, int millis)Constructs a new time with the given values. The values are not checked.- Since:
- SuperWaba 3.5
-
-
Method Detail
-
update
public void update()
Updates the internal fields with the current timestamp.- Since:
- TotalCross 1.23
-
getTime
public long getTime() throws InvalidDateExceptionReturns the number of millis since 1/1/1970- Throws:
InvalidDateException- Since:
- TotalCross 2.1
-
getTimeLong
public long getTimeLong()
Returns the time in the format YYYYMMDDHHMMSS as a long value. It does not include the millis.- Since:
- SuperWaba 4.0
-
getSQLLong
public long getSQLLong()
Returns the time in the format YYYYMMDDHHmmSSmmm as a long value. It does include the millis.- Since:
- TotalCross 2.0
-
getSQLString
public java.lang.String getSQLString()
Returns this date in the formatYYYY-MM-DD HH:mm:SS.mmm- Since:
- TotalCross 2.0
-
getSQLString
public java.lang.String getSQLString(java.lang.StringBuffer sb)
Returns this date in the formatYYYY-MM-DD HH:mm:SS.mmm- Since:
- TotalCross 2.0
-
toString
public java.lang.String toString()
Returns the time in format specified in totalcross.sys.Settings (does NOT include the date neither the millis). To return the date, use class totalcross.util.Date. So, to get a String with the date and time, use:Time t = new Time(); String dateAndTime = new Date(t) + " " + t;
- Overrides:
toStringin classjava.lang.Object
-
toString
public 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). To return the date, use class totalcross.util.Date. So, to get a String with the date and time, use:Time t = new Time(); String dateAndTime = new Date(t) + " " + t;
- Since:
- TotalCross 1.15
-
dump
public java.lang.StringBuffer dump(java.lang.StringBuffer sb, java.lang.String timeSeparator, boolean includeMillis)Dumps the time into the given StringBuffer.- Since:
- TotalCross 1.24
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
toIso8601
public java.lang.String toIso8601()
Converts this time object to a string in the Iso8601 format:YYYYMMDDTHH:MM:SS
.- Since:
- SuperWaba 5.61
-
isValid
public boolean isValid()
Returns true if the time is valid. Note that the date part is NOT checked, only hour, minute, second and millis are checked against valid ranges.- Since:
- TotalCross 1.22
-
inc
public void inc(int hours, int minutes, int seconds)Increments or decrements the fields below. Note that this method DOES update the day/month/year fields, constructing a Date object and manipulating it; consider reusing a Time object if you use this method.
Parameters can be positive (to increment), zero (to keep it), or negative (to decrement).- Since:
- TotalCross 1.24
-
-