How can you convert the UNIX timestamp (that is in the form of a number denoting timestamp) into date, time(hours, minutes, seconds) in Objective-C?
Convert from epoch to human-readable date String date = new java.text.SimpleDateFormat("MM/dd/yyyy HH:mm:ss").format(new java.util.Date (epoch*1000)); Epoch in seconds, remove '*1000' for milliseconds. myString := DateTimeToStr(UnixToDateTime(Epoch)); Where Epoch is a signed integer.
Unix time is a system for representing a point in time. It is the number of seconds that have elapsed since January 1st, 1970 00:00:00 UTC.
For output, use an NSDateFormatter
. To extract values for other purposes, use NSDateComponents
. eg:
NSDate *date = [NSDate dateWithTimeIntervalSince1970:1234567];
NSDateComponents *weekdayComponents = [[NSCalendar currentCalendar] components:NSWeekdayCalendarUnit fromDate:date];
int weekday = [weekdayComponents weekday];
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