问题
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!
回答1:
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:
NSDateFormatter formatting
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]
来源:https://stackoverflow.com/questions/19401045/generating-date-logic-for-uipickerview