D
D
deleted-mezhevikin2014-06-27 18:48:31
Objective-C
deleted-mezhevikin, 2014-06-27 18:48:31

How to parse EST date using NSDate?

There is a date in the form of a string Tue, 18 Dec 2007 24:00:00 EST , you need to get nsdate from it.
Tried like this:

NSDate *date = [@"Tue, 18 Dec 2007 24:00:00 EST" dateWithFormat:@"EEE, dd MMMM yyyy HH:mm:ss ZZZ"];

- (NSDate *)dateWithFormat:(NSString *)format
{
    NSDateFormatter *formatter = [NSDateFormatter new];
    [formatter setDateFormat:format];
    [formatter setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]];
    return [formatter dateFromString:self];
}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Denis Morozov, 2014-06-27
@deleted-mezhevikin

1. you need MMM, not MMMM
2. 24:00:00 - there is no such time

NSDateFormatter *formatter = [NSDateFormatter new];
[formatter setDateFormat:@"EEE, dd MMM yyyy HH:mm:ss 'EST'"];
[formatter setTimeZone:[NSTimeZone timeZoneWithName:@"EST"]];
NSLog(@"%@", [formatter dateFromString:@"Tue, 18 Dec 2007 23:00:00 EST"]);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question