Inherits from NSDateFormatter
Declared in RKDotNetDateFormatter.h
RKDotNetDateFormatter.m

Overview

A subclass of NSDateFormatter that serves as translator between ASP.NET date serializations in JSON strings and NSDate objects. This is useful for properly mapping these dates from an ASP.NET driven backend. NOTE – DO NOT attempt to use setDateFormat: on this class. It will return invalid results.

Tasks

  • + dotNetDateFormatter

    Instantiates an autoreleased RKDotNetDateFormatter object with the timezone set to UTC (Greenwich Mean Time).

  • + dotNetDateFormatterWithTimeZone:

    Instantiates an autoreleased RKDotNetDateFormatter object. The supplied timeZone, such as one produced with [NSTimeZone timeZoneWithName:@“UTC”], is only used during calls to stringFromDate:, for a detailed explanation see dateFromString:

  • – dateFromString:

    Returns an NSDate object from an ASP.NET style date string respresentation, as seen in JSON. Acceptable examples are:

    /Date(1112715000000-0500)/
    /Date(1112715000000)/
    /Date(-1112715000000)/
    

    Where 1112715000000 is the number of milliseconds since January 1, 1970 00:00 GMT/UTC, and -0500 represents the timezone offset from GMT in 24-hour time. Negatives milliseconds are treated as dates before January 1, 1970.

  • – stringFromDate:

    Returns an ASP.NET style date string from an NSDate, such as /Date(1112715000000+0000)/ Where 1112715000000 is the number of milliseconds since January 1, 1970 00:00 GMT/UTC, and +0000 is the timezone offset from GMT in 24-hour time.

Class Methods

dotNetDateFormatter

Instantiates an autoreleased RKDotNetDateFormatter object with the timezone set to UTC (Greenwich Mean Time).

+ (RKDotNetDateFormatter *)dotNetDateFormatter

Return Value

An autoreleased RKDotNetDateFormatter object

Declared In

RKDotNetDateFormatter.h

dotNetDateFormatterWithTimeZone:

Instantiates an autoreleased RKDotNetDateFormatter object. The supplied timeZone, such as one produced with [NSTimeZone timeZoneWithName:@“UTC”], is only used during calls to stringFromDate:, for a detailed explanation see dateFromString:

+ (RKDotNetDateFormatter *)dotNetDateFormatterWithTimeZone:(NSTimeZone *)timeZone

Parameters

timeZone

An NSTimeZone object.

Return Value

An autoreleased RKDotNetDateFormatter object

Declared In

RKDotNetDateFormatter.h

Instance Methods

dateFromString:

Returns an NSDate object from an ASP.NET style date string respresentation, as seen in JSON. Acceptable examples are:

/Date(1112715000000-0500)/
/Date(1112715000000)/
/Date(-1112715000000)/

Where 1112715000000 is the number of milliseconds since January 1, 1970 00:00 GMT/UTC, and -0500 represents the timezone offset from GMT in 24-hour time. Negatives milliseconds are treated as dates before January 1, 1970.

- (NSDate *)dateFromString:(NSString *)string

Parameters

string

The ASP.NET style string, /Date(1112715000000-0500)/

Return Value

An NSDate object

Discussion

NOTE NSDate objects do not have timezones, and you should never change an actual date value based on a timezone offset. However, timezones are important when presenting dates to the user. Therefore, If an offset is present in the ASP.NET string (it should be), we actually ignore the offset portion because we want to store the actual date value in its raw form, without any pollution of timezone information. If, on the other hand, there is no offset in the ASP.NET string, we assume GMT (+0000) anyway. In summation, for this class setTimeZone: is ignored except when using stringFromDate:

Declared In

RKDotNetDateFormatter.h

stringFromDate:

Returns an ASP.NET style date string from an NSDate, such as /Date(1112715000000+0000)/ Where 1112715000000 is the number of milliseconds since January 1, 1970 00:00 GMT/UTC, and +0000 is the timezone offset from GMT in 24-hour time.

- (NSString *)stringFromDate:(NSDate *)date

Parameters

date

An NSDate

Return Value

The ASP.NET style string, /Date(1112715000000-0500)/

Discussion

NOTE GMT (+0000) is assumed otherwise specified via setTimeZone:

Declared In

RKDotNetDateFormatter.h