2017-07-02 11 views
0

AFNetworking3の解析済み日付を表示して、1時間前などの経過日数ではなく、完全な日付を表示しようとしています。ここhttp://mkssab.com/api/indexAFNetworking3から解析された日付を表示し、経過した時間のみを表示する

+0

あなたが最初NSDateFormatterを使用してNSDateオブジェクトに(日付を表す)NSStringのを変換する必要があります。あなたはそこを見ることができますhttps://stackoverflow.com/questions/20487465/how-to-convert-nsdate-in-to-relative-format-as-today-yesterday-a-week-ago – Larme

答えて

0

はNSDateに文字列を変換して現在の日付と日付W/Bの差を計算するためのコードである: 私は、これは、JSONデータのリンクである

allData = [responseObject objectForKey:@"data"]; 
    NSDictionary *data = [allData objectAtIndex:indexPath.row]; 
    cell.created_at.text = [data objectForKey:@"created_at"]; 

完全な日付を取得するためにこれを使用しました。

//This piece of code get the date from created date 
NSDateFormatter* formatter = [[NSDateFormatter alloc] init]; 
[formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"]; 
NSDate* createdOn = [formatter dateFromString:[data objectForKey:@"created_at"]]; 

//This piece of code calculates the difference b/w created date and current date. 
NSTimeInterval interval = [createdOn timeIntervalSinceDate:NSDate.date]; 
NSInteger hours = interval/3600; 

参考:https://developer.apple.com/documentation/foundation/nsdate?language=objc

+0

これは動作しません「YYYY」と「hh」の代わりに「yyyy」と「HH」を使用する必要があります。 – Larme

+0

指摘していただきありがとうございます。そうです。私の答えを編集しました – pkallu

関連する問題