Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Converting UNIX timestamp into date, hours, minutes, seconds

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?

like image 695
neha Avatar asked May 12 '10 11:05

neha


People also ask

How do you convert timestamp to normal time?

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.

Is Unix timestamp in seconds or milliseconds?

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.


1 Answers

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];
like image 127
Paul Lynch Avatar answered Nov 15 '22 17:11

Paul Lynch