Search code examples
iphoneiosipaddatetimeepoch

calculate epoch time in iPad


I have an array which contains time in HH:mm:ss format.

I want to convert this into epoch time. To convert a particular time into epoch, date along with time should be passed.

I want to pass today's date along with the time from array.

For example 09:15:30 (date 22/12/2011) which is a string, should be converted into 1324525530000 (corresponding epoch value)

How should I convert this ??

Any help is appreciated.


Solution

  • Maybe you can get an idea looking at this snippet:

    NSDateFormatter * dateFormatter = [[NSDateFormatter alloc] initWithSafeDateFormat:@"dd/MM/yyyy HH:mm:ss"];
    NSDate *date = [dateFormatter dateFromString:dateString];
    NSTimeInterval epoch = [date timeIntervalSince1970];
    

    Anyway you can have a look to NSDateFormatter and NSDate in the reference docs.