Home Tutorial Iphone Examples iPhone Current Date, iPhone Current Date Application

 
 

Share on Google+Share on Google+
iPhone Current Date, iPhone Current Date Application
Posted on: August 24, 2009 at 12:00 AM
Advertisement
In this application we are going to display current date on label by using Window based application.

   CurrentDate Application

In thisapplication we are going to display current dateon label by using Window based application.

Creating avariable (mlabel), declared as IBOutlet andalso property is declared.

.h filewill look like this:

#import<UIKit/UIKit.h>

@interfaceCurrentDateAppDelegate : NSObject <UIApplicationDelegate>

{

   UIWindow*window;

   IBOutletUILabel*mlabel;

   UIDatePicker*myDatePicker;

}

 

@property(nonatomic,retain)IBOutletUIWindow*window;

@property(nonatomic,retain)IBOutletUILabel*mlabel;

 

@end 

In this wesynthesize variable and also to display current date we use Stringwhich isdeclared in NSDateFormatter and isallocated and next is thestyle format

     NSDateFormatter*dateFormatter =

   [[[NSDateFormatteralloc]init] autorelease];

   [dateFormatter setDateStyle:NSDateFormatterMediumStyle];

   [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

   NSDate*date =[NSDatedate];  //toprint date

   NSString*formattedDateString = [dateFormatterstringFromDate:date];

to displaythe value in label we use declared:  

mlabel.text=[NSString stringWithFormat:@"%@",formattedDateString];

 

.m filewill look like this:

#import"CurrentDateAppDelegate.h"

@implementationCurrentDateAppDelegate

@synthesizewindow, mlabel;

-(void)applicationDidFinishLaunching:(UIApplication*)application

 

{

   [windowmakeKeyAndVisible];

   

   NSDateFormatter*dateFormatter =

   [[[NSDateFormatteralloc]init] autorelease];

   [dateFormatter setDateStyle:NSDateFormatterMediumStyle];

   [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

   NSDate*date =[NSDatedate];

   NSString*formattedDateString = [dateFormatterstringFromDate:date];

   NSLog(@"formattedDateStringfor locale %@: %@", [[dateFormatter locale]localeIdentifier],formattedDateString);

   mlabel.text=[NSString stringWithFormat:@"%@",formattedDateString];

}

-(void)dealloc

{

   [windowrelease];

   [mlabelrelease];

   [superdealloc];

}

@end

Downloadcode from here.

Advertisement

Related Tags for iPhone Current Date, iPhone Current Date Application :


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: August 24, 2009

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com