开发者

Create timestamp of now as NSNumber in objective-c

Ho开发者_StackOverflow中文版w can I get timestamp as NSNumber? I only need something like this: 1232885280


NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];
// NSTimeInterval is defined as double
NSNumber *timeStampObj = [NSNumber numberWithDouble: timeStamp];


Time Intervals Since 1970

NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];

Time Intervals Since Now

NSTimeInterval timeStamp = [[NSDate date] timeIntervalSinceNow];

Time Intervals Since Date

NSDateComponents* comps = [[NSDateComponents alloc]init];
comps.year = 2014;
comps.month = 3;
comps.day = 31;
NSCalendar* calendar = [NSCalendar currentCalendar];
NSDate* date = [calendar dateFromComponents:comps];

NSTimeInterval timeStamp = [[NSDate date] timeIntervalSinceDate:date];

Time Intervals Since Reference Date

The Intervals between the date object and 00:00:00 UTC on 1 january 2001.

NSTimeInterval timeStamp = [[NSDate date] timeIntervalSinceReferenceDate];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜