com.altova.types.DateTime
This class enables you to process XML attributes or elements that have date and time types, such as xs:dateTime.
Constructors
Name | Description | |
---|---|---|
public DateTime() | Initializes a new instance of the DateTime class to an empty value. | |
public DateTime(DateTime newvalue) | Initializes a new instance of the DateTime class to the DateTime value supplied as argument. | |
public DateTime(int newyear, int newmonth, int newday, int newhour, int newminute, int newsecond, double newpartsecond, int newoffsetTZ) | Initializes a new instance of the DateTime class to the year, month, day, hour, minute, second, the fractional part of the second, and timezone supplied as arguments. The fractional part of the second newpartsecond must be between 0 and 1. The timezone offset newoffsetTZ can be either positive or negative and is expressed in minutes. | |
public DateTime(int newyear, int newmonth, int newday, int newhour, int newminute, int newsecond, double newpartsecond) | Initializes a new instance of the DateTime class to the year, month, day, hour, minute, second, and the fractional part of a second supplied as arguments. | |
public DateTime(int newyear, int newmonth, int newday) | Initializes a new instance of the DateTime class to the year, month, and day supplied as arguments. | |
public DateTime(Calendar newvalue) | Initializes a new instance of the DateTime class to the java.util.Calendar value supplied as argument. |
Methods
Name | Description | |||||||
---|---|---|---|---|---|---|---|---|
static DateTime now() | Returns the current time as a DateTime object. | |||||||
static DateTime parse(String s) | Returns a DateTime object parsed from the string value supplied as argument. For example, the following sample string values would be converted successfully to a DateTime object:
2015-11-24T12:54:47.969+01:00 2015-11-24T12:54:47 2015-11-24 | |||||||
int getDay() | Returns the day of the current DateTime instance. | |||||||
int getHour() | Returns the hour of the current DateTime instance. | |||||||
int getMillisecond() | Returns the millisecond of the current DateTime instance, as an integer value. | |||||||
int getMinute() | Returns the minute of the current DateTime instance. | |||||||
int getMonth() | Returns the month of the current DateTime instance. | |||||||
double getPartSecond() | Returns the fractional part of the second of the current DateTime instance, as a double value. The return value is greater than zero and smaller than one, for example:
0.313 | |||||||
int getSecond() | Returns the second of the current DateTime instance. | |||||||
int getTimezoneOffset() | Returns the timezone offset, in minutes, of the current DateTime instance. For example, the timezone "UTC-01:00" would be returned as:
-60 | |||||||
Calendar getValue() | Returns the current DateTime instance as a java.util.Calendar value. | |||||||
int getWeekday() | Returns the day in week of the current DateTime instance. Values range from 0 through 6, where 0 is Monday (ISO-8601). | |||||||
int getYear() | Returns the year of the current DateTime instance. | |||||||
int hasTimezone() | Returns information about the timezone of the current DateTime instance. Possible return values are:
| |||||||
void setDay( int nDay ) | Sets the day of the current DateTime instance to the value supplied as argument. | |||||||
void setHasTimezone( int nHasTZ ) | Sets the timezone information of the current DateTime instance to the value supplied as argument. This method can be used to strip the timezone information or set the timezone to UTC (Coordinated Universal Time). Valid values for the nHasTZ argument:
| |||||||
void setHour( int nHour ) | Sets the hour of the current DateTime instance to the value supplied as argument. | |||||||
void setMinute( int nMinute ) | Sets the minute of the current DateTime instance to the value supplied as argument. | |||||||
void setMonth( int nMonth ) | Sets the month of the current DateTime instance to the value supplied as argument. | |||||||
void setPartSecond( double nPartSecond ) | Sets the fractional part of the second of the current DateTime instance to the value supplied as argument. | |||||||
void setSecond( int nSecond ) | Sets the second of the current DateTime instance to the value supplied as argument. | |||||||
void setTimezoneOffset( int nOffsetTZ ) | Sets the timezone offset of the current DateTime instance to the value supplied as argument. The value nOffsetTZ must be an integer (positive or negative) and must be expressed in minutes. | |||||||
void setYear( int nYear ) | Sets the year of the current DateTime instance to the value supplied as argument. | |||||||
String toString() | Returns the string representation of the current DateTime instance, for example:
2015-11-24T15:50:56.968+01:00 |
Examples
Before using the following code listings in your program, ensure the Altova types are imported:
import com.altova.types.*; |
The following code listing illustrates various ways to create DateTime objects:
protected static void DateTimeExample1() DateTime dt3 = DateTime.parse("2015-11-24T12:54:47.969+01:00"); |
The following code listing illustrates getting values from DateTime objects:
protected static void DateTimeExample2() |
The following code listing illustrates changing the timezone offset of a DateTime object:
protected static void DateTimeExample3() |