iOS_时间戳与时间间的互相转化

来源:互联网 发布:mac os ps 破解版 编辑:程序博客网 时间:2024/05/21 14:00

时间转时间戳

    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];
0 0
原创粉丝点击