Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get current system time?

Whats the best way to get the current time (HH:MM:SS) using Objective-C. I would guess I should be looking at NSDate & NSDateFormatter. I had a quick glance at the docs and it looked a little more convoluted than I expected, so I thought I would check here to make sure I was on the right track.

gary

like image 479
fuzzygoat Avatar asked Feb 22 '10 18:02

fuzzygoat


People also ask

How can I get current system time?

To retrieve the current system date and time in local time, use the GetLocalTime function.

How do I get the current time in spring boot?

Here is the code. . . . public static void getCurrentTimeUsingCalendar() { Calendar cal = Calendar. getInstance(); Date date=cal. getTime(); DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss"); String formattedDate=dateFormat.

How do I get the current date in Java 8?

You can get the time from the LocaldateTime object using the toLocalTime() method. Therefore, another way to get the current time is to retrieve the current LocaldateTime object using the of() method of the same class. From this object get the time using the toLocalTime() method.


1 Answers

NSDate * now = [NSDate date]; NSDateFormatter *outputFormatter = [[NSDateFormatter alloc] init]; [outputFormatter setDateFormat:@"HH:mm:ss"]; NSString *newDateString = [outputFormatter stringFromDate:now]; NSLog(@"newDateString %@", newDateString); [outputFormatter release]; 
like image 93
Ben Zotto Avatar answered Sep 24 '22 21:09

Ben Zotto