Generating Date Logic for UIPickerView

為{幸葍}努か 提交于 2019-12-13 05:07:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!