時間轉時間戳
NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];
NSLog(@"timeSp:%@",timeSp); //時間戳的值
時間戳轉時間(1)
NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:1296035591];
NSLog(@"1296035591 = %@",confromTimesp);
NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];
NSLog(@"confromTimespStr = %@",confromTimespStr);
時間戳轉時間(2)
NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterMediumStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
[formatter setDateFormat:@"yyyyMMddHHMMss"];
NSDate *date = [formatter dateFromString:@"1283376197"];
NSLog(@"date1:%@",date);
[formatter release];