I want to convert my timestamp value 1308031456
to NSDate
format (which yields the value Tue, 14 Jun 2011 06:04:16 GMT
in online web conversion). How would I convert between the two programmatically?
use this: NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp/1000]; then convert your date in the format you want.
You can simply use the fromtimestamp function from the DateTime module to get a date from a UNIX timestamp. This function takes the timestamp as input and returns the corresponding DateTime object to timestamp.
OBJ - C: Use dateWithTimeIntervalSince1970:,
NSDate *date = [NSDate dateWithTimeIntervalSince1970:timeStamp];
SWIFT: Use init(timeIntervalSince1970:)
let date = NSDate(timeIntervalSince1970:timeStamp)
You can use the use the method dateWithTimeIntervalSince1970:
to convert the timestamp you've which is the epoch time.
NSDate * myDate = [NSDate dateWithTimeIntervalSince1970:1308031456];
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