显示当前时间 [英] Display current time in epoch
本文介绍了显示当前时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试显示当前时间(以纪元为准),我不确定这是否正确,但是我确定不是,因为它给了我一个错误:
I'm trying to display the current time in epoch, i'm not sure if this is correct, but i'm sure it's not since it's giving me an error:
NSDate *currentDate = [NSDate date];
NSDate *epochDate = [NSDate dateWithTimeIntervalSince1970:currentDate];
是否知道如何实现此目标?
Any idea of how to accomplish this?
推荐答案
NSTimeInterval epoch = [[NSDate date] timeIntervalSince1970];
NSLog(@"%f", epoch);
或者更好的是,这只是时间的整数部分:
Or better yet, this gives just the integer part of the time:
int epoch = round([[NSDate date] timeIntervalSince1970]);
NSLog(@"%d", epoch);
这篇关于显示当前时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文