After going through this iphone SDK example, you will be able to show the current time on UILable. In this example we have used a UILable to show the output(current time) of the application and an UIButton(for button action).
After going through this iphone SDK example, you will be able to show the current time on UILable. In this example we have used a UILable to show the output(current time) of the application and an UIButton(for button action).Iphone Current Time Example
After going through this iphone SDK example, you will be able to show the current time on UILable. In this example we have used a UILable to show the output(current time) of the application and an UIButton(for button action).
Button actions are generally defined into ".h" file
method: "-(IBAction)currentdate:(id)sender;", and action methods are written in the ".m" file. Action method:
-(IBAction)currentdate:(id)sender { NSDate* date = [NSDate date]; //Create the dateformatter object NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease]; //Set the required date format [formatter setDateFormat:@"HH:MM:SS"]; //Get the string date NSString* str = [formatter stringFromDate:date]; //Display on the console NSLog(str); //Set in the lable [dateLabel setText:str]; } |
The application will look like this:
You can also download the complete code of "current time application in iphone"