关于时间戳

来源:互联网 发布:网络歌曲谢谢你陪着我 编辑:程序博客网 时间:2024/05/20 19:28

调用以下方法即可

-(NSString *)dateWithString:(NSString *)string{


    /**

     设置你想要的时间格式

     */

    NSDateFormatter * fotmatter = [[NSDateFormatteralloc]init];

    [fotmatter setDateStyle:NSDateFormatterMediumStyle];

    [fotmatter setTimeStyle:NSDateFormatterShortStyle];

//

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

//n

    NSTimeInterval time = [string doubleValue];

    

    NSDate * date = [NSDatedateWithTimeIntervalSince1970:time];

    

    NSString * currentString = [fotmatter stringFromDate:date];

    

    return currentString;

}

    


0 0