「Objective-Cの入門」タイムスタンプをするサンプルプログラム
Objective-Cコード:
-(NSString *)timeStamp:(NSString *)data
{
//タイムスタンプ
NSDateFormatter *formatter = [[NSDateFormatter alloc] init] ;
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
[formatter setTimeZone:timeZone];
// タイムスタンプから時間に変換
NSString *str = [NSString stringWithFormat:@"%@",data];
NSTimeInterval time=[str doubleValue];
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:time];
//NSLog(@"1383523892 = %@",confromTimesp);
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
//NSLog(@"confromTimespStr = %@",confromTimespStr);
NSString *timeString =[confromTimespStr substringWithRange:NSMakeRange(0,10)];
return timeString;
}