Up
Authors
- Richard Frith-Macdonald (
richard@brainstorm.co.uk
)
-
Version: 26606
Date: 2008-06-08 11:38:33 +0100 (Sun, 08 Jun 2008)
Copyright: (C) 1998 Free Software Foundation, Inc.
- Declared in:
- Foundation/NSDateFormatter.h
- Conforms to:
- NSCoding
- NSCopying
Availability: MacOS-X 10.0.0
Class for generating text
representations of
NSDate
s and
NSCalendarDate
s, and for converting strings into instances of
these objects. Note that
NSDate
and
NSCalendarDate
do contain some string conversion methods, but using this class provides more control over conversion.
See the
NSFormatter
documentation for description of the basic methods for formatting and parsing that are available.
The basic format of a format string uses "%" codes to represent components of the date. Thus, for example, @"%b %d, %Y"
specifies strings similar to "June 18, 1991". The full list of codes is as follows:
- %%
-
a '%' character
- %a
-
abbreviated weekday name
- %A
-
full weekday name
- %b
-
abbreviated month name
- %B
-
full month name
- %c
-
shorthand for "%X %x", the locale format for date and time
- %d
-
day of the month as a decimal number (01-31)
- %e
-
same as %d but does not print the leading 0 for days 1 through 9 (unlike strftime()
, does not print a leading space)
- %F
-
milliseconds as a decimal number (000-999)
- %H
-
hour based on a 24-hour clock as a decimal number (00-23)
- %I
-
hour based on a 12-hour clock as a decimal number (01-12)
- %j
-
day of the year as a decimal number (001-366)
- %m
-
month as a decimal number (01-12)
- %M
-
minute as a decimal number (00-59)
- %p
-
AM/PM designation for the locale
- %S
-
second as a decimal number (00-59)
- %w
-
weekday as a decimal number (0-6), where Sunday is 0
- %x
-
date using the date representation for the locale, including the time zone (produces different results from strftime())
- %X
-
time using the time representation for the locale (produces different results from strftime())
- %y
-
year without century (00-99)
- %Y
-
year with century (such as 1990)
- %Z
-
time zone name (such as Pacific Daylight Time; produces different results from strftime())
- %z
-
time zone offset in hours and minutes from GMT (HHMM)
Instance Variables
Method summary
- (BOOL)
allowsNaturalLanguage;
Availability: MacOS-X 10.0.0
Returns whether initialized to support natural
language formatting. If YES
,
string-to-object conversion will attempt
to process strings as natural language dates, such as
"yesterday", or "first Tuesday of next month"
if straight format-based conversion fails.
- (
NSString*)
dateFormat;
Availability: MacOS-X 10.0.0
Returns format string initialized with, specifying
how dates are formatted, for object-to-string
conversion, and how they are parsed, for
string-to-object conversion. For example,
@"%b %d, %Y"
specifies strings similar
to "June 18, 1991".
- (id)
initWithDateFormat: (
NSString*)format
allowNaturalLanguage: (BOOL)flag;
Availability: MacOS-X 10.0.0
Initialize with given specifier string
format. See class description for how to
specify a format string. If
flag is YES
, string-to-object
conversion will attempt to process strings as
natural language dates, such as "yesterday", or
"first Tuesday of next month" if straight
format-based conversion fails.
Instance Variables for NSDateFormatter Class
@protected BOOL _allowsNaturalLanguage;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
@protected NSString* _dateFormat;
Availability: MacOS-X 10.0.0
Warning the underscore at the start of the
name of this instance variable indicates that, even
though it is not technically private, it is
intended for internal use within the package, and
you should not use the variable in other code.
Up