生成UIPickerView的日期逻辑 [英] Generating Date Logic for UIPickerView

查看:224
本文介绍了生成UIPickerView的日期逻辑的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我很喜欢ios开发。



我正在使用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];

您可以在这里找到格式化程序及其含义:



NSDateFormatter格式



今天得到:

  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:

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]

这篇关于生成UIPickerView的日期逻辑的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆