IOS学习 UIDatePicker 包含时间格式转换
来源:互联网 发布:易语言文本处理源码 编辑:程序博客网 时间:2024/06/04 23:22
@implementation HomeViewController
- (void)viewDidLoad {
[superviewDidLoad];
// Do any additional setup after loading the view.
UIDatePicker *datePicker = [[UIDatePickeralloc]initWithFrame:CGRectMake(30,self.view.bounds.size.height-261,0, 0)];
datePicker.minimumDate = [NSDatedateWithTimeIntervalSinceNow:-60*60*24*365*10];//10年前
datePicker.maximumDate = [NSDatedateWithTimeIntervalSinceNow:+60*60*24*365*10];//10年后
datePicker.date = [NSDatedate];
datePicker.tag =101;
datePicker.datePickerMode =UIDatePickerModeDateAndTime;
/* UIDatePickerModeTime, 显示时间,分上下午
UIDatePickerModeDate, 显示日期,月日年
UIDatePickerModeDateAndTime, 显示日期和时间,星期
UIDatePickerModeCountDownTimer, 24小时制显示时间 */
[self.viewaddSubview:datePicker];
UIButton *btn = [[UIButtonalloc]initWithFrame:CGRectMake(100,100, 100, 40)];
[btn setTitle:@"显示时间"forState:UIControlStateNormal];
btn.backgroundColor = [UIColorpurpleColor];
[btn addTarget:selfaction:@selector(click)forControlEvents:UIControlEventTouchUpInside];
[self.viewaddSubview:btn];
}
-(void)click{
UIDatePicker *dateP = (UIDatePicker *)[self.viewviewWithTag:101];
//获取选中的时间
NSDate *date = dateP.date;
//时间格式化
NSDateFormatter *dateFormatter = [[NSDateFormatteralloc]init];
[dateFormatter setDateStyle:@"yyyy-mm-dd"];
NSString *dateStr = [dateFormatter stringFromDate:date];
NSLog(@"%@",dateStr);
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:@"提示"message:[NSStringstringWithFormat:@"你选中的时间是:%@",dateStr]delegate:selfcancelButtonTitle:@"取消"otherButtonTitles:@"确定",nil];
[alertView show];
}
- IOS学习 UIDatePicker 包含时间格式转换
- ios 时间格式转换
- iOS 时间格式(时间格式转换)
- iOS的UIDatePicker时间控件
- iOS 时间/ 日期选择器 UIDatePicker
- IOS --- 日期时间格式 转换
- iOS的时间格式转换
- iOS时间格式转换总结
- ios UTC 时间格式转换
- IOS 时间格式 时间转换 大总结
- IOS 时间格式 时间转换 大总结
- IOS 时间格式 时间转换 大总结
- iOS 时间格式 时间转换 大总结
- UIDatePicker 中文显示和日期格式转换
- iOS中如何将UIDatePicker的时间转换成24小时制
- ios设置UIDatePicker日期为中文格式
- iOS--UIDatePicker 时间选择器 的使用方法详细
- ios常用技术 - UIDatePicker时间选择器基础
- 如何在终端输出带颜色的字体?PHP CLI输出颜色
- activity的启动模式
- Linux开启mysql远程连接的设置步骤
- Android消息推送1----原始的socket长链接
- HDU1285拓扑排序实例分析
- IOS学习 UIDatePicker 包含时间格式转换
- strlen()与sizeof
- linux 进程的虚拟地址和内核中的虚拟地址有什么关系
- class.getResource()用法
- FTP 服务器搭建
- Hadoop数据压缩
- 最简真分数
- 一个不安分的肥猫程序猿
- Android下使用正则表达式