IOS 1970到指定时间的秒 转化为指定的日期

View Code
+ (NSString *) secondSince1970ToStr:(long long int)seconds
{
    NSDate *date = [NSDate dateWithTimeIntervalSince1970:seconds];
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *str = [formatter stringFromDate:date];
    [formatter release];
    NSLog(@"str %@",str);
    return str;
}

 [test secondSince1970ToStr:1360144800];

输出 2013-02-06 18:00:00

 

View Code
+ (NSString *) secondToStr:(long long int)milliseconds
{
    long long int tarSeconds = milliseconds;
    NSDate *tarDate = [NSDate dateWithTimeIntervalSince1970:tarSeconds];
    return [self stringFromDate:tarDate withFormat:@"yyyy-MM-dd HH:mm:ss"];
    
}

 

posted @ 2013-01-30 20:08  菜鸟程序猿  阅读(433)  评论(0编辑  收藏  举报