For example: assume NSDate tempdate = "05-23-2013"
. I want this value to be converted into milliseconds.
How can I do this with Objective-C?
There is a similar post here and here.
Basically you have get the second form the reference date (1 January 2001, GMT) and multiply it with 1000.
NSTimeInterval seconds = [NSDate timeIntervalSinceReferenceDate];
double milliseconds = seconds*1000;
Cheers!
The timeIntervalSince1970
will return seconds from 1970. There are other timeIntervalSince methods if needed.
https://developer.apple.com/library/mac/documentation/Cocoa/Reference/Foundation/Classes/NSDate_Class/Reference/Reference.html#//apple_ref/occ/instm/NSDate/timeIntervalSince1970
For reverse conversion, I mean to say from milliseconds to NSDate, refer this stackoverflow article. Convert milliseconds to NSDate
Hope it ll solve your issue.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With