开发者

Create timestamp of now as NSNumber in objective-c

开发者 https://www.devze.com 2023-01-11 02:56 出处:网络
Ho开发者_StackOverflow中文版w can I get timestamp as NSNumber? I only need something like this: 1232885280NSTimeInterval timeStamp = [[NSDate date] timeIntervalSince1970];

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

精彩评论

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