iOS NSDateFormatter NSDate for “now” with timezone

In iOS I needed “now” as a string to use in an HTTP POST. This is as short as I can see to make it:

NSDateFormatter *df = [[NSDateFormatter alloc] init];
[df setDateFormat:@"yyyy-MM-dd HH:mm:ss ZZ"];
NSString *d = [df stringFromDate:
                  [NSDate dateWithTimeIntervalSinceNow:0]];

The first time you do something it might be painful. Here’s to hoping your pain is less than mine :)

Be Sociable, Share!

    Post a Comment

    Your email is never published nor shared. Required fields are marked *


    × six = 12