生成UIPickerView的日期逻辑 [英] Generating Date Logic for UIPickerView
问题描述
我正在使用UIPickerView制作自定义日期戳。
我必须显示从今天到下一个20天的日期&我完成了生成这些日期和将它们分配给数组。这些日期格式为:Oct 16,2013。
但我的问题是我想显示工作日(在3人物),月刊天,即Wed,Oct 16在UIpickerView上。而在本周的一周中,仅显示天数,即今天,明天,周五,周六,周日,周一,周二,下周,星期三,十月二十三日等。
提前谢谢!任何帮助将不胜感激!
假设您有一个名为myDate的NSDate对象,您需要格式化日期使用日期格式化程序:
NSDateFormatter * dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@EEE,LLL d];
NSString * myString = [dateFormat stringFromDate:myDate];
您可以在这里找到格式化程序及其含义:
今天得到:
NSdate * today = [NSDate date]
明天:
code> NSDate * tomorrow = [NSDate dateWithTimeInterval:(24 * 60 * 60)sinceDate:[NSDate date]]
明天后:
NSDate * afterTomorrow = [NSDate dateWithTimeInterval:(24 * 60 * 60)sinceDate:明天]
I am new to ios development.
I am making a custom datepicker using UIPickerView.
I have to show dates ranging from today to next 20 days & I am done with generating those dates & assigning them to an array.Those Dates have format: Oct 16,2013.
But my problem is I want to show Weekday(in 3 characters),Month & day i.e. Wed,Oct 16 on UIpickerView. And for one current week only Days are shown i.e today,tomorrow,Fri,Sat,Sun,Mon,Tue and for Next Week it would have Wed,Oct 23 and so on.
Thanks in advance! Any help would be greatly appreciated!
Assuming that you have a NSDate object called myDate for example, You need to format the dates using a date formater:
NSDateFormatter *dateFormat = [[NSDateFormatter alloc] init];
[dateFormat setDateFormat:@"EEE, LLL d"];
NSString *myString = [dateFormat stringFromDate:myDate];
You can find the formatters and what they mean here:
To get today:
NSdate *today = [NSDate date];
Tomorrow:
NSDate *tomorrow = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:[NSDate date]]
After tomorrow:
NSDate *afterTomorrow = [NSDate dateWithTimeInterval:(24*60*60) sinceDate:tomorrow]
这篇关于生成UIPickerView的日期逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!