Home Tutorial Iphone Examples Iphone Current Time Example

 
 

Share on Google+Share on Google+
Iphone Current Time Example
Posted on: September 7, 2009 at 12:00 AM
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

Advertisement

Related Tags for Iphone Current Time Example:


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.

Posted on: September 7, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com