NSDateFormatter formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"YYYY-MM-dd"]; //設置時區 NSTimeZone timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"]; NSDate *datenow = [NSDate date];//如今時間 //轉換成時間YYYY-MM-dd NSString *nowtimeStr = [formatter stringFromDate:datenow];orm
//轉換時間戳 NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[datenow timeIntervalSince1970]];
NSLog(@"時間戳%@",timeSp);string
//時間戳轉時間的方法 NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:@"時間戳"]; NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];it
//form