PDFDateFormatter

public final class PDFDateFormatter : Formatter

The PDFDateFormatter class generates and parses string representations of dates that are used as the PDF metadata. For example, when setting a creation date of a document, the Date value is converted to String using this formatter.

Example:

Assume we have 2017, March 27, 18:32:30 in the YEKT time zone (UTC/GMT +5 hours). PDFDateFormatter will transform this date as D:20170327183230+05'00’ and vice versa.

  • Creates an instance of the formatter.

    Declaration

    Swift

    public override init()
  • Creates an instance of the formatter using the provided unarchiver. This is not required for PDFDateFormatter and is kept only for satisfying the Formatter abstract class requirements.

    Declaration

    Swift

    public required init?(coder aDecoder: NSCoder)
  • Converts the given value of type Date to a string representation using the TimeZone.current time zone.

    Declaration

    Swift

    public override func string(for obj: Any?) -> String?

    Parameters

    obj

    The date to convert to a string.

    Return Value

    The string representation of the given date, or nil if obj is not a date.

  • Converts the given date to a string with respect to the provided timeZone.

    Declaration

    Swift

    public func string(from date: Date, timeZone: TimeZone = .current) -> String

    Parameters

    date

    The date to convert to a string.

    timeZone

    The time zone to encode in the resulting string. Default value is TimeZone.current.

    Return Value

    The string representation of the given date.

  • Decodes the given string into the date it represents.

    Declaration

    Swift

    public func date(from string: String) -> Date?

    Parameters

    string

    The string representation of a date in the standard PDF date format (e. g. D:20170327183230+05'00’)

    Return Value

    The Date value that string represents, or nil if string is invalid.