2012-01-10 9 views

Odpowiedz

16

Można użyć

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

W date dostaniesz faktyczną datę. Dalsze można sformatować go w formacie „dd/mm/rrrr” za pomocą

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

W nDate dostaniesz żądaną datę w sformatowanej sposób.

+0

Dziękuję bardzo. Działa świetnie! – OzBoz

0

Spróbuj tego ...

NSDate *date=[[NSDate alloc] initWithTimeIntervalSinceReferenceDate:gettingdate]; 
NSDateFormatter *dateFormat = [[NSDateFormatter alloc]init]; 
[dateFormat setDateFormat:@"dd-MM-yyyy HH:mm:SS"]; 
NSString *newdate = [dateFormat stringFromDate:date]; 
0
//Use of Function 
textFiled.text = [self displayDate:[[NSString stringWithFormat:@"%@",[[[AllKeys valueForKey:@"Date"] componentsSeparatedByString:@"\"]]]] 


// Millisecond to Date conversion 
- (NSDate *)displayDate:(double)unixMilliseconds { 

    NSDate *date = [NSDate dateWithTimeIntervalSince1970:unixMilliseconds/1000.]; 
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; 

    [dateFormatter setDateStyle:NSDateFormatterShortStyle]; 
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle]; 
    [dateFormatter setLocale:[NSLocale currentLocale]]; 

    NSLog(@"The date is %@", [dateFormatter stringFromDate:date]); 
    // NSDate *returnValue = [dateFormatter stringFromDate:date]; 
    return date; 
} 
+0

'textField.text' spodziewa się NSString, ale ty przypisujesz obiekt NSDate. Co to jest "AllKeys" i co ma to zrobić z '/ Date (1326067200000) /' – vikingosegundo

Powiązane problemy