从 UIPickerView 获取月份
我有一个独特的要求。在我的应用程序中,我只需要从选择器中获取月份。由于日期选择器无法实现此功能,因此我只列出了几个月的自定义选择器。客户选择月份后所需的日期格式是 1-Jan-2011 到 1-feb-2011
基本上,月份是来自 uipickerview 的唯一内容,而日期和年份是静态的。 有人可以帮我吗?我尝试过一些代码。
NSString *dateString = [[NSString alloc ]initWithFormat:@"2011-%d-1 GMT+05:30", monthFromPickerAsInteger];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"yy-MM-DD z4"];
NSDate *dateFromString = [[NSDate alloc] init];
// ta-daaa!
dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@", dateFromString);
I have a unique requirement. In my app I need to get only the month from picker. Since Date picker cannot implement this, I made the custom picker listing only months. The required format of the date after the customer selects a month is 1-Jan-2011 to 1-feb-2011
Basically, the month is the only thing that is coming from uipickerview and the day and year are static.
Can someone help me out? Some code I have tried.
NSString *dateString = [[NSString alloc ]initWithFormat:@"2011-%d-1 GMT+05:30", monthFromPickerAsInteger];
NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
// this is imporant - we set our input date format to match our input string
// if format doesn't match you'll get nil from your string, so be careful
[dateFormatter setDateFormat:@"yy-MM-DD z4"];
NSDate *dateFromString = [[NSDate alloc] init];
// ta-daaa!
dateFromString = [dateFormatter dateFromString:dateString];
NSLog(@"%@", dateFromString);
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我猜你想这样做
I guess you want to do this,