iPhone Current Date, iPhone Current Date Application


 

iPhone Current Date, iPhone Current Date Application

In this application we are going to display current date on label by using Window based application.

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

0

@synthesizewindow, mlabel;

-(void)applicationDidFinishLaunching:(UIApplication*)application

 

1

{

   [windowmakeKeyAndVisible];

   

2

   NSDateFormatter*dateFormatter =

   [[[NSDateFormatteralloc]init] autorelease];

   [dateFormatter setDateStyle:NSDateFormatterMediumStyle];

3

   [dateFormatter setTimeStyle:NSDateFormatterNoStyle];

   NSDate*date =[NSDatedate];

   NSString*formattedDateString = [dateFormatterstringFromDate:date];

4

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

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

5

}

-(void)dealloc

{

6

   [windowrelease];

   [mlabelrelease];

   [superdealloc];

7

}

@end

Downloadcode from here.

8

Ads