如何在不同的文本字段中显示时间段?
我有三个文本字段,我想在其中显示当前时间。在第一个文本字段中,它仅显示小时,在第二个文本字段中,它仅显示分钟,在最后一个文本字段中,它显示上午或下午。为了获取当前时间,我使用此代码,但如何根据我的要求显示? 代码...
- (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];
}
提前致谢...
I have three text field in which i want to show 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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)