每日一练:OC中的对象概念1

本文介绍了一个使用Objective-C编写的程序,该程序展示了如何获取当前日期和时间、如何以不同格式打印时间戳,并计算从1970年1月1日到当前时间的秒数。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

#import <Foundation/Foundation.h>


int main(int argc, const char * argv[]) {

    @autoreleasepool {

        // insert code here...

        NSDate *now = [NSDate date];

        //时间指针格式

        NSLog(@"The time for now is :%p. \n", now);

        //时间数据格式

        NSLog(@"The time for now is %@ \n", now);

        //计算1970年1月1日 12点中到现在的时间

        double seconds = [now timeIntervalSince1970];

        

        NSLog(@"From 1970-01-01 12:00 to now is :%f seconds\n", seconds);

        

    }

    return 0;

}


Result:

2018-03-10 14:15:08.101631+0800 TOCNSDatea[37619:12858536] The time for now is :0x10045f2c0.

2018-03-10 14:15:08.101949+0800 TOCNSDatea[37619:12858536] The time for now is Sat Mar 10 14:15:08 2018

2018-03-10 14:15:08.101967+0800 TOCNSDatea[37619:12858536] From 1970-01-01 12:00 to now is :1520662508.101608 seconds

Program ended with exit code: 0


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值