开发者

How display section of time in different text field?

I have three text field in which i want to sho开发者_如何学Pythonw the current time. In the first text field,it shows only hours , in second text field it shows only minute and in last one it shows am or pm. For getting current time I use this code but how do I show according to my requirement? code...

- (void)viewDidLoad {

NSDate* date = [NSDate date];

//Create the dateformatter object

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

//Set the required date format

[formatter setDateFormat:@"HH:MM"];

//Get the string date

NSString* str = [formatter stringFromDate:date];

//Display on the console

NSLog(@"%@",str);

//Set in the lable

time_label.text=[NSString stringWithFormat:@"%@ AM",str];
[super viewDidLoad];

}

Thanks in advance...


NSDate* date = [NSDate date];

//Create the dateformatter object

NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

//Set the required date format

[formatter setDateFormat:@"hh MM a"];

//Get the string date

NSString* str = [formatter stringFromDate:date];

//Display on the console

NSLog(@"%@",str);
NSMutableArray *Arr=[str componentsSeparatedByString:@" "];

textFeild1.text=[Arr objectAtIndex:0]; //hoursTextFeild
textFeild2.text=[Arr objectAtIndex:1]; //minutesTextFeild
textFeild3.text=[Arr objectAtIndex:2];//Am/Pm TextFeild


- (void)viewDidLoad {

    NSDate* date = [NSDate date];

    //Create the dateformatter object

    NSDateFormatter* formatter = [[[NSDateFormatter alloc] init] autorelease];

    //Set the required date format

    [formatter setDateFormat:@"HH:MM"];

    //Get the string date

    NSString* str = [formatter stringFromDate:date];

    //Display on the console

    NSLog(@"%@",str);

    //Set in the label
   //seperate its components
    NSMutableArray *array = [str componentsSeperatedByString:@" "];

   [firstTextField setText:[array objectAtIndex:0]];
   [secondTextField setText:[array objectAtIndex:1]];
   [thirdTextField setText:@"AM/PM"];


    [super viewDidLoad];
    }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜