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
PDFDateFormatterand is kept only for satisfying theFormatterabstract class requirements.Declaration
Swift
public required init?(coder aDecoder: NSCoder) -
Converts the given value of type
Dateto a string representation using theTimeZone.currenttime zone.Declaration
Swift
public override func string(for obj: Any?) -> String?Parameters
objThe date to convert to a string.
Return Value
The string representation of the given date, or
nilifobjis not a date. -
Converts the given
dateto a string with respect to the providedtimeZone.Declaration
Swift
public func string(from date: Date, timeZone: TimeZone = .current) -> StringParameters
dateThe date to convert to a string.
timeZoneThe 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
stringinto the date it represents.Declaration
Swift
public func date(from string: String) -> Date?Parameters
stringThe string representation of a date in the standard PDF date format (e. g.
D:20170327183230+05'00’
)Return Value
The
Datevalue thatstringrepresents, ornilifstringis invalid.
View on GitHub
PDFDateFormatter Class Reference