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
@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