Class NSDate

All Implemented Interfaces:
Cloneable, Comparable<NSObject>

public class NSDate extends NSObject
The NSDate class wraps a date.
See Also:
  • Field Details

  • Constructor Details

    • NSDate

      public NSDate(byte[] bytes)
      Creates new NSDate instance from its binary representation.
      Parameters:
      bytes - The binary date representation.
    • NSDate

      public NSDate(byte[] bytes, int startIndex, int endIndex)
      Creates a new NSDate instance from its binary representation.
      Parameters:
      bytes - The byte array containing the date data.
      startIndex - The index within the array at which the date data begins.
      endIndex - The index within the array at which the data date ends.
    • NSDate

      public NSDate(String textRepresentation) throws ParseException
      Creates a new NSDate instance from is textual representation. The textual representation must adhere to one of the following patterns. For XML property lists: yyyy-MM-dd'T'HH:mm:ss'Z' For ASCII property lists: yyyy-MM-dd HH:mm:ss Z
      Parameters:
      textRepresentation - The textual representation of the date.
      Throws:
      ParseException - If the date could not be parsed, i.e. it does not match the expected pattern.
    • NSDate

      public NSDate(Date d)
      Creates a new NSDate instance.
      Parameters:
      d - The date.
  • Method Details

    • parseDateString

      private static Date parseDateString(String textRepresentation) throws ParseException
      Parses a date string and creates a Java Date object from it. This function is synchronized because the underlying SimpleDateFormat instances are not thread-safe.
      Parameters:
      textRepresentation - The date string as found in an ASCII or XML property list
      Returns:
      The parsed Date
      Throws:
      ParseException - If the given string cannot be parsed.
      See Also:
    • makeDateString

      private static String makeDateString(Date date)
      Generates a string representation of a Java Date object. The string is formatted according to the specification for XML property list dates.
      Parameters:
      date - The date which should be represented.
      Returns:
      The string representation of the date.
    • makeDateStringGnuStep

      private static String makeDateStringGnuStep(Date date)
      Generates a string representation of a Java Date object. The string is formatted according to the specification for GnuStep ASCII property list dates.
      Parameters:
      date - The date which should be represented.
      Returns:
      The string representation of the date.
    • getDate

      public Date getDate()
      Gets the date.
      Returns:
      The date.
    • equals

      public boolean equals(Object obj)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • clone

      public NSDate clone()
      Description copied from class: NSObject
      Creates and returns a deep copy of this instance.
      Specified by:
      clone in class NSObject
      Returns:
      A clone of this instance.
    • toXML

      void toXML(StringBuilder xml, int level)
      Description copied from class: NSObject
      Generates the XML representation of the object (without XML headers or enclosing plist-tags).
      Specified by:
      toXML in class NSObject
      Parameters:
      xml - The StringBuilder onto which the XML representation is appended.
      level - The indentation level of the object.
    • toBinary

      void toBinary(BinaryPropertyListWriter out) throws IOException
      Description copied from class: NSObject
      Generates the binary representation of the object.
      Specified by:
      toBinary in class NSObject
      Parameters:
      out - The output stream to serialize the object to.
      Throws:
      IOException - If an I/O error occurs while writing to the stream or the object structure contains data that cannot be saved.
    • toString

      public String toString()
      Generates a string representation of the date.
      Overrides:
      toString in class Object
      Returns:
      A string representation of the date.
      See Also:
    • toJavaObject

      public Object toJavaObject()
      Description copied from class: NSObject
      Converts this NSObject into an equivalent object of the Java Runtime Environment.
      • NSArray objects are converted to arrays.
      • NSDictionary objects are converted to objects extending the Map class.
      • NSSet objects are converted to objects extending the Set class.
      • NSNumber objects are converted to primitive number values (int, long, double or boolean).
      • NSString objects are converted to String objects.
      • NSData objects are converted to byte arrays.
      • NSDate objects are converted to Date objects.
      • UID objects are converted to byte arrays.
      Specified by:
      toJavaObject in class NSObject
      Returns:
      A native java object representing this NSObject's value.
    • compareTo

      public int compareTo(NSObject o)
    • toASCII

      protected void toASCII(StringBuilder ascii, int level)
      Description copied from class: NSObject
      Generates the ASCII representation of this object. The generated ASCII representation does not end with a newline. Complies with the Old-Style ASCII Property Lists definition.
      Specified by:
      toASCII in class NSObject
      Parameters:
      ascii - The StringBuilder onto which the ASCII representation is appended.
      level - The indentation level of the object.
    • toASCIIGnuStep

      protected void toASCIIGnuStep(StringBuilder ascii, int level)
      Description copied from class: NSObject
      Generates the ASCII representation of this object in the GnuStep format. The generated ASCII representation does not end with a newline.
      Specified by:
      toASCIIGnuStep in class NSObject
      Parameters:
      ascii - The StringBuilder onto which the ASCII representation is appended.
      level - The indentation level of the object.