IOS 时间处理

作者: JakieZhang | 来源:发表于2016-12-03 09:31 被阅读491次

    NSDate*date = [NSDatedate];

    NSLog(@"%@", date);//世界标准时间

    NSLog(@"%@",localDate());

    NSLog(@"%@", [datelocalDate]);

    NSLog(@"%@", [NSDate localDate]);

    //获取比当前时间快30秒的指定时间

    NSDate*date1 = [NSDate dateWithTimeIntervalSinceNow:30];

    NSLog(@"%@", date);

    NSLog(@"%@", date1);

    NSDate*date2 = [NSDate dateWithTimeIntervalSinceNow:-30];

    NSLog(@"%@", date2);

    //间隔

    NSTimeInterval seconds = [date timeIntervalSince1970];//获取的是1970年1月1日至今的总秒数

    NSLog(@"%lg", seconds);

    NSDate*date3 = [NSDate dateWithTimeIntervalSinceNow:-60];

    seconds = [date3timeIntervalSinceNow];//从指定时间至今的总秒数

    NSLog(@"%lg", seconds);

    NSDate*time1 = [NSDate dateWithTimeIntervalSinceNow:-60*60*24];

    NSDate*time2 = [NSDate dateWithTimeIntervalSinceNow:60*60*24];

    seconds = [time1 timeIntervalSinceDate: time2];

    NSLog(@"%lg", seconds);

    //指定输出格式

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

    df.dateFormat=@"yyyy年MM月dd日HH:mm:ss EEE";

    NSString*str = [df stringFromDate: date];

    NSLog(@"%@", str);

    相关文章

      网友评论

        本文标题:IOS 时间处理

        本文链接:https://www.haomeiwen.com/subject/rbxcmttx.html