Class DateTimeAttribute


public class DateTimeAttribute extends StringAttribute

A concrete class specializing Attribute for Date Time (DT) attributes.

Though an instance of this class may be created using its constructors, there is also a factory class, AttributeFactory.

See Also:
  • Field Details

    • MAX_LENGTH_SINGLE_VALUE

      protected static final int MAX_LENGTH_SINGLE_VALUE
      See Also:
  • Constructor Details

  • Method Details

    • getMaximumLengthOfSingleValue

      public final int getMaximumLengthOfSingleValue()
      Specified by:
      getMaximumLengthOfSingleValue in class StringAttribute
    • getVR

      public byte[] getVR()

      Get the value representation of this attribute (DT).

      Overrides:
      getVR in class Attribute
      Returns:
      'D','T' in ASCII as a two byte array; see ValueRepresentation
    • allowRepairOfIncorrectLength

      protected final boolean allowRepairOfIncorrectLength()
      Overrides:
      allowRepairOfIncorrectLength in class StringAttribute
    • allowRepairOfInvalidCharacterReplacement

      protected final boolean allowRepairOfInvalidCharacterReplacement()
      Overrides:
      allowRepairOfInvalidCharacterReplacement in class StringAttribute
    • isCharacterInValueValid

      public final boolean isCharacterInValueValid(int c) throws DicomException
      Overrides:
      isCharacterInValueValid in class StringAttribute
      Throws:
      DicomException
    • getFormattedString

      public static String getFormattedString(Date date, TimeZone timezone, boolean tzSuffix)

      Get a DICOM format DT String value from a Java Date.

      Will format the Date for the specified timezone.

      Parameters:
      date - the Java Date to format
      timezone - the Java TimeZone to use
      tzSuffix - whether or not to append the time zone suffix
      Returns:
      a DICOM formatted DT value
    • getFormattedString

      public static String getFormattedString(Date date, TimeZone timezone)

      Get a DICOM format DT String value from a Java Date.

      Will format the Date for the specified timezone.

      Will include the timezone suffix.

      Parameters:
      date - the Java Date to format
      timezone - the Java TimeZone to use
      Returns:
      a DICOM formatted DT value
    • getFormattedStringUTC

      public static String getFormattedStringUTC(Date date)

      Get a DICOM format DT String value from a Java Date.

      Will format the Date for the UTC timezone, converting from whatever timezone is specified in the supplied Date if not UTC.

      Parameters:
      date - the Java Date to format
      Returns:
      a DICOM formatted DT value
    • getFormattedStringDefaultTimeZone

      public static String getFormattedStringDefaultTimeZone(Date date)

      Get a DICOM format DT String value from a Java Date.

      Will format the Date for the default timezone, converting from whatever timezone is specified in the supplied Date if not the default.

      Parameters:
      date - the Java Date to format
      Returns:
      a DICOM formatted DT value
    • getFormattedString

      public static String getFormattedString(Date date)

      Get a DICOM format DT String value from a Java Date.

      Will format the Date for the default timezone, converting from whatever timezone is specified in the supplied Date if not the default.

      Parameters:
      date - the Java Date to format
      Returns:
      a DICOM formatted DT value
    • getDateFromFormattedString

      public static Date getDateFromFormattedString(String dateString) throws ParseException

      Get a Java Date from a DICOM format DT String value.

      Parameters:
      dateString - the date to parse
      Returns:
      a Java Date
      Throws:
      ParseException - if incorrectly encoded
    • getDateFromFormattedString

      public static Date getDateFromFormattedString(AttributeList list, AttributeTag dateTag, AttributeTag timeTag) throws ParseException, DicomException

      Get a Java Date from a DICOM format DT String value.

      Will use the TimezoneOffsetFromUTC if present in the AttributeList, else will assume UTC (not whatever the local time zone happens to be).

      Parameters:
      list - the list containing the attributes
      dateTag - the tag of the DA attribute
      timeTag - the tag of the TM attribute
      Returns:
      a Java Date
      Throws:
      ParseException - if incorrectly encoded
      DicomException - if date attribute is missing or empty
    • getTimeZone

      public static TimeZone getTimeZone(String dicomTimeZone)

      Get a Java TimeZone from a DICOM format String time zone.

      E.g. from +0500 or -0700, the last component of a DateTime attribute value, or the value of the DICOM attribute TimezoneOffsetFromUTC.

      Parameters:
      dicomTimeZone - the String DICOM format time zone
      Returns:
      a Java TimeZone representing the supplied time zone, or the GMT zone if it cannot be understood
    • getTimeZone

      public static String getTimeZone(TimeZone javaTimeZone, Date javaDate)

      Get a DICOM format String time zone from a Java TimeZone on a particular Java Date .

      E.g. from +0500 or -0700, the last component of a DateTime attribute value, or the value of the DICOM attribute TimezoneOffsetFromUTC.

      Parameters:
      javaTimeZone - the TimeZone time zone
      javaDate - the Date used to establish whether daylight savings is in effect or not
      Returns:
      a DICOM format String time zone representing the supplied time zone on the supplied date
    • getCurrentTimeZone

      public static String getCurrentTimeZone()

      Get a DICOM format String time zone representation of the current timezone.

      E.g. from +0500 or -0700, the last component of a DateTime attribute value, or the value of the DICOM attribute TimezoneOffsetFromUTC.

      Returns:
      a DICOM format String time zone representing the current time zone on the current date
    • getTimeInMilliSecondsSinceEpoch

      public static long getTimeInMilliSecondsSinceEpoch(String dateTime) throws ParseException

      Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the DT value.

      Parameters:
      dateTime - the string to parse
      Returns:
      the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date; may be a ludicrous value if string not formatted correctly
      Throws:
      ParseException - if incorrectly encoded
    • getTimeInMilliSecondsSinceEpoch

      public static long getTimeInMilliSecondsSinceEpoch(AttributeList list, AttributeTag dateTag, AttributeTag timeTag) throws ParseException, DicomException

      Returns the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by the combination of the DA and TM values of the specified pair of attributes.

      Will use the TimezoneOffsetFromUTC if present in the AttributeList, else will assume UTC (not whatever the local time zone happens to be).

      Parameters:
      list - the list containing the attributes
      dateTag - the tag of the DA attribute
      timeTag - the tag of the TM attribute
      Returns:
      the number of milliseconds since January 1, 1970, 00:00:00 GMT represented by this date
      Throws:
      ParseException - if incorrectly encoded
      DicomException - if date attribute is missing or empty