Share on Google+Share on Google+

Iphone Current Time Example

Advertisement
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" 

Download Here

Advertisements

Posted on: September 7, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.