org.opcfoundation.ua.builtintypes
Class DateTime

java.lang.Object
  extended by org.opcfoundation.ua.builtintypes.DateTime
All Implemented Interfaces:
Serializable, Comparable<DateTime>

public class DateTime
extends Object
implements Serializable, Comparable<DateTime>

OPC UA DateTime. The OPC UA dateTime is defined as follows (OPCUA Part 3) 7.29 UtcTime This primitive DataType is used to define Coordinated Universal Time (UTC) values. All time values conveyed between servers and clients in OPC UA are UTC values. Clients must provide any conversions between UTC and local time. This DataType is represented as a 64-bit signed integer which represents the number of 100 nanosecond intervals since January 1, 1601. [UA Part 6] defines details about this DataType.

Author:
Jouni.Aro@prosys.fi
See Also:
Serialized Form

Field Summary
static String DEFAULT_STR_FORMAT
          Constant DEFAULT_STR_FORMAT="%TD %TT.%07d %TZ"
static NodeId ID
          Constant ID
static String ISO_8601_STR_FORMAT
          Constant ISO_8601_STR_FORMAT="%TF %TT.%07d %TZ"
static DateTime MAX_VALUE
          Constant MAX_VALUE
static DateTime MIN_VALUE
          Constant MIN_VALUE
static long OffsetToGregorianCalendarZero
          Constant OffsetToGregorianCalendarZero=116444736000000000L
 
Constructor Summary
DateTime()
          Constructs a new DateTime value, initializing it with the current UTC time.
DateTime(Calendar value)
          Constructs a new DateTime value, is initializing it with a Calendar value.
DateTime(int year, int month, int day, int hour, int minute, int second)
          Constructs a new DateTime value, initializing it with the given time value (in UTC timezone).
DateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond)
          Constructs a new DateTime value, initializing it with the given time value (in UTC timezone).
DateTime(int year, int month, int day, int hour, int minute, int second, int nanosecond, TimeZone timeZone)
          Constructs a new DateTime value, initializing it with the given time value (in the defined timezone).
DateTime(long value)
          Constructs a new DateTime value, initializing it with an OPC UA time value with a resolution of 100 nanoseconds.
 
Method Summary
 int compareTo(DateTime o)
          
static DateTime currentTime()
          currentTime.
 boolean equals(Object obj)
          
static DateTime fromMillis(long value)
          Create a new DateTime instance from standard Java milliseconds since the beginning of epoch, January 1, 1970 UTC.
 GregorianCalendar getCalendar(TimeZone timezone)
          Return the time as a calendar value.
 GregorianCalendar getLocalCalendar()
          getLocalCalendar.
 long getMilliSeconds()
          Get milliseconds between the time and midnight, January 1, 1601 UTC.
static String getStrFormat()
          Get the format used for toString()
 long getTimeInMillis()
          Get standard Java milliseconds between the time and midnight, January 1, 1970 UTC.
 GregorianCalendar getUtcCalendar()
          getUtcCalendar.
 long getValue()
          Get 1/10 microseconds (1 unit = 100 nanoseconds) between the time and midnight, January 1, 1601 UTC.
 int hashCode()
          
static boolean isUseLocalTimeInToString()
          If this is true, then DateTime.toString should print local timestamps and Utc if this is false.
static DateTime parseDateTime(String s)
          Parse a DateTime value from a string.
static void setStrFormat(String strFormat)
          Set the format used for toString()
static void setUseLocalTimeInToString(boolean useLocalTimeInToString)
          If this is true, then DateTime.toString should print local timestamps and Utc if this is false.
 String toString()
          toString.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DEFAULT_STR_FORMAT

public static String DEFAULT_STR_FORMAT
Constant DEFAULT_STR_FORMAT="%TD %TT.%07d %TZ"


ISO_8601_STR_FORMAT

public static String ISO_8601_STR_FORMAT
Constant ISO_8601_STR_FORMAT="%TF %TT.%07d %TZ"


ID

public static final NodeId ID
Constant ID


OffsetToGregorianCalendarZero

public static final long OffsetToGregorianCalendarZero
Constant OffsetToGregorianCalendarZero=116444736000000000L

See Also:
Constant Field Values

MIN_VALUE

public static final DateTime MIN_VALUE
Constant MIN_VALUE


MAX_VALUE

public static final DateTime MAX_VALUE
Constant MAX_VALUE

Constructor Detail

DateTime

public DateTime()
Constructs a new DateTime value, initializing it with the current UTC time.


DateTime

public DateTime(long value)
Constructs a new DateTime value, initializing it with an OPC UA time value with a resolution of 100 nanoseconds.

Parameters:
value - a long.

DateTime

public DateTime(Calendar value)
Constructs a new DateTime value, is initializing it with a Calendar value.

Parameters:
value - a Calendar object.

DateTime

public DateTime(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int nanosecond,
                TimeZone timeZone)
Constructs a new DateTime value, initializing it with the given time value (in the defined timezone).

Creates a GregorianCalendar using the parameters year..second; sets the TimeZone and adds nanoSeconds.

Note: that month is 0-based, and the values correspond to the constants, Calendar.JANUARY, etc.

Parameters:
year - a int.
month - a int.
day - a int.
hour - a int.
minute - a int.
second - a int.
nanosecond - a int.
timeZone - a TimeZone object.

DateTime

public DateTime(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second,
                int nanosecond)
Constructs a new DateTime value, initializing it with the given time value (in UTC timezone).

Creates a GregorianCalendar using the parameters year..second and adds nanoSeconds.

Note: that month is 0-based, and the values correspond to the constants, Calendar.JANUARY, etc.

Parameters:
year - a int.
month - a int.
day - a int.
hour - a int.
minute - a int.
second - a int.
nanosecond - a int.

DateTime

public DateTime(int year,
                int month,
                int day,
                int hour,
                int minute,
                int second)
Constructs a new DateTime value, initializing it with the given time value (in UTC timezone).

Creates a GregorianCalendar using the parameters year..second.

Note: that month is 0-based, and the values correspond to the constants, Calendar.JANUARY, etc.

Parameters:
year - a int.
month - a int.
day - a int.
hour - a int.
minute - a int.
second - a int.
Method Detail

getValue

public long getValue()
Get 1/10 microseconds (1 unit = 100 nanoseconds) between the time and midnight, January 1, 1601 UTC.

Returns:
time value

getMilliSeconds

public long getMilliSeconds()
Get milliseconds between the time and midnight, January 1, 1601 UTC.

Returns:
time in milliseconds since January 1, 1601 UTC midnight

getTimeInMillis

public long getTimeInMillis()
Get standard Java milliseconds between the time and midnight, January 1, 1970 UTC. This equals to the value returned by the respective Calendar instance, returned by getCalendar.

Returns:
milliseconds since January 1, 1970 UTC midnight

toString

public String toString()

toString.

Overrides:
toString in class Object
Returns:
a String object.

getUtcCalendar

public GregorianCalendar getUtcCalendar()

getUtcCalendar.

Returns:
the dateTime converted to a new GregorianCalendar in UTC TimeZone.

getLocalCalendar

public GregorianCalendar getLocalCalendar()

getLocalCalendar.

Returns:
the dateTime converted to a new GregorianCalendar in local TimeZone.

getCalendar

public GregorianCalendar getCalendar(TimeZone timezone)
Return the time as a calendar value.

Parameters:
timezone - The desired TimeZone for the calendar
Returns:
a new GregorianCalendar instance, initialized to the value of the DateTime.

hashCode

public int hashCode()

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)

Overrides:
equals in class Object

compareTo

public int compareTo(DateTime o)

Specified by:
compareTo in interface Comparable<DateTime>

currentTime

public static DateTime currentTime()

currentTime.

Returns:
an instance of DateTime with the current time.

parseDateTime

public static DateTime parseDateTime(String s)
                              throws ParseException
Parse a DateTime value from a string. The valid string formats is the xs:dateTime format, as defined in [Part 6., 5.3.1.6]:
All DateTime values shall be encoded as UTC times or with the time zone explicitly specified.

Correct:
2002-10-10T00:00:00+05:00
2002-10-09T19:00:00Z

Incorrect:
2002-10-09T19:00:00

Parameters:
s - the string to parse
Returns:
a new DateTime value, corresponding to the timestamp
Throws:
ParseException - if the DateTime cannot be parsed from s

fromMillis

public static DateTime fromMillis(long value)
Create a new DateTime instance from standard Java milliseconds since the beginning of epoch, January 1, 1970 UTC.

Parameters:
value - a long.
Returns:
a DateTime object.

getStrFormat

public static String getStrFormat()
Get the format used for toString()

Returns:
the format

setStrFormat

public static void setStrFormat(String strFormat)
Set the format used for toString()

Parameters:
strFormat - new format

isUseLocalTimeInToString

public static boolean isUseLocalTimeInToString()
If this is true, then DateTime.toString should print local timestamps and Utc if this is false. Default is false.

Returns:
a boolean.

setUseLocalTimeInToString

public static void setUseLocalTimeInToString(boolean useLocalTimeInToString)
If this is true, then DateTime.toString should print local timestamps and Utc if this is false. Default is false.

Parameters:
useLocalTimeInToString - a boolean.


Copyright © 2018. All rights reserved.