2012-01-10 60 views

回答

16

您可以使用

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

date你會得到的實際日期。另外,你可以通過使用

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

nDate你會得到你想要的日期在一個格式化的方式在「MM/DD/YYYY」格式進行格式化。

+0

非常感謝。它很棒! – OzBoz 2012-01-10 09:43:48

0

嘗試......

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'期待一個的NSString,但你分配的NSDate對象。什麼是'AllKeys',它與'/ Date(1326067200000)/'有什麼關係 – vikingosegundo 2013-07-11 14:42:17