xcode NSDateFormatter setTitle

索引サイト
日付の処理


appl***.h




#import

@interface Windows_based_630AppDelegate : NSObject {
UIWindow *window;
UIButton *btDate;
UITextField *txDate1;
UITextField *txDate2;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;

@property (nonatomic, retain) IBOutlet UIButton *btDate;
@property (nonatomic, retain) IBOutlet UITextField *txDate1;
@property (nonatomic, retain) IBOutlet UITextField *txDate2;

- (IBAction)touch1:(id)sender;

@end

システムデートと一ヶ月前(31日前)の日付
appl***.m



#import "Windows_based_630AppDelegate.h"

@implementation Windows_based_630AppDelegate

@synthesize window;

@synthesize btDate;
@synthesize txDate1;
@synthesize txDate2;

- (IBAction)touch1:(id)sender
{
NSDateFormatter *dateFormatter = [ [NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"Y/M/d"];

NSString *dateString = [dateFormatter stringFromDate:[NSDate date] ];
txDate1.text = dateString;

NSDate *date2;
date2 = [NSDate dateWithTimeIntervalSinceNow:-31*24*60*60];

dateString = [dateFormatter stringFromDate:date2];
txDate2.text = dateString;
}




- (void)dealloc {
[window release];
[btDate release];
[txDate1 release];
[txDate2 release];
[super dealloc];
}


ボタンへの文字セット




#import "Window_based_650AppDelegate.h"

@implementation Window_based_650AppDelegate

@synthesize window;

@synthesize bt_SetDate;
@synthesize bt_00;
@synthesize bt_01;
@synthesize bt_02;
@synthesize bt_03;
@synthesize bt_04;
@synthesize bt_05;
@synthesize bt_06;
@synthesize bt_07;

@synthesize tx_check;

- (IBAction)touch_01:(id)sender
{
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
[dateFormatter setDateFormat:@"M/d"];

NSDate *w_date[8];
NSString *w_dateString[8];

for (int idx=0;idx<8;idx++)
{
w_date[idx] = [NSDate dateWithTimeIntervalSinceNow:idx*24*60*60];
w_dateString[idx] = [dateFormatter stringFromDate:w_date[idx]];
}
tx_check.text = @"push check";
[bt_00 setTitle:w_dateString[0] forState:UIControlStateNormal];
[bt_01 setTitle:w_dateString[1] forState:UIControlStateNormal];
[bt_02 setTitle:w_dateString[2] forState:UIControlStateNormal];
[bt_03 setTitle:w_dateString[3] forState:UIControlStateNormal];
[bt_04 setTitle:w_dateString[4] forState:UIControlStateNormal];
[bt_05 setTitle:w_dateString[5] forState:UIControlStateNormal];
[bt_06 setTitle:w_dateString[6] forState:UIControlStateNormal];
[bt_07 setTitle:w_dateString[7] forState:UIControlStateNormal];
}




AX