时间戳

    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];

    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];   

//    1

    NSDate *date = [NSDate date];

    NSLog(@"时间  %@",[formatter stringFromDate:date]);      

    NSString *timeSp = [NSString stringWithFormat:@"%d", (long)[[formatter dateFromString:[formatter stringFromDate:date]] timeIntervalSince1970]];

    NSLog(@"---timeSP---- %@ ",timeSp);

//    2

    NSTimeInterval time=[timeSp doubleValue];

    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];

    NSLog(@"date:%@",[detaildate description]);    

    NSDate *confromTimesp = [NSDate dateWithTimeIntervalSince1970:[timeSp doubleValue]];

    NSLog(@"1296035591  = %@",confromTimesp);

    NSString *confromTimespStr = [formatter stringFromDate:confromTimesp];

    NSLog(@"confromTimespStr =  %@",confromTimespStr);

posted @ 2015-05-24 11:40  lol挂  阅读(333)  评论(0)    收藏  举报