OzBoz OzBoz - 1 year ago 99
Objective-C Question

How can I convert system millisecond to the Date in objective-c

I am getting the date from web service like /Date(1326067200000)/ , how can I convert it to the date like DD.MM.YYYY?

Answer Source

You can use

    NSString *actDate = @"/Date(1326067200000)/";
    NSString *nDate = [[[[actDate componentsSeparatedByString:@"("] objectAtIndex:1] componentsSeparatedByString:@")"] objectAtIndex:0];
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:([nDate doubleValue] / 1000)];

In date you will get the actual date. Further you can format it in "MM/dd/yyyy" format by using

    NSDateFormatter *dtfrm = [[NSDateFormatter alloc] init];
    [dtfrm setDateFormat:@"MM/dd/yyyy"];
    nDate = [dtfrm stringFromDate:date];

In nDate you will get your desired date in a formatted way.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download