ylliX - Online Advertising Network

How to add unix timestamp to NSDictionary

Recently I had an NSDate object which had to be convered to unix timestamp and added to NSDictionary. But, what a surprise – I can’t add anything which is not object, and time_t is C element. So what to do? Solution as usual is very simple:

NSDate *date = your date here;
NSTimeInterval ts= [date timeIntervalSince1970]
myDictionary[@"myTimestamp"] = @(ts);

As result of this snipped, you will have NSNumber object in your dictionary instead of NSDate

Leave a Reply