【问题标题】:Is it possible for a date picker to present year/month/day + day name?日期选择器是否可以显示年/月/日+日期名称?
【发布时间】:2012-05-10 10:24:58
【问题描述】:

是否可以将日期名称添加到日期选择器? 例如表盘会显示:

(星期日)3 | 11 | 2012

有可能吗? 谢谢!

【问题讨论】:

  • 你解决了吗?我也有同样的问题......

标签: iphone objective-c ios5 ios4


【解决方案1】:

我认为您不能将 DayName(例如星期日)与 Year-Month-Day 一起使用,直到您没有完全自定义,但您可以通过以下代码获取带有日期的日期,这可能会对您有所帮助。

在Xib中绑定以下两个IBOutlet。

并将方法 -(IBAction)GetDateWithDay 与 DatePicker 与 ValueChange 属性绑定

在.h文件中

IBOutlet UIDatePicker* datePicker;
IBOutlet UILabel* lblDate;

在 .m 文件中

-(IBAction)GetDateWithDay
{

     NSDate* dt = datePicker.date;
     NSDateFormatter* df = [[[NSDateFormatter alloc]init]autorelease];
     [df setDateFormat:@"yyyy-MM-dd"];

     NSCalendar *calendar = [NSCalendar currentCalendar];
     NSInteger units = NSYearCalendarUnit | NSMonthCalendarUnit | NSDayCalendarUnit | NSWeekdayCalendarUnit;
     NSDateComponents *components = [calendar components:units fromDate:dt];
     NSInteger year = [components year];
     NSInteger day = [components day];

     NSDateFormatter *weekDay = [[[NSDateFormatter alloc] init] autorelease];
     [weekDay setDateFormat:@"EEEE"];

     NSDateFormatter *calMonth = [[[NSDateFormatter alloc] init] autorelease];
     [calMonth setDateFormat:@"MM"];

     lblDate.text = [NSString stringWithFormat:@"%@, %i-%@-%i",[weekDay stringFromDate:dt], day, [calMonth stringFromDate:dt], year];

}

【讨论】:

    【解决方案2】:

    阅读this document对你有帮助

    【讨论】:

    • 谢谢,但我正在寻找一个日期选择器,它会显示 - 也 - 工作日名称。只是为了获得工作日的代码在这里对我没有帮助..
    【解决方案3】:
    【解决方案4】:

    您可以使用选项 DD。 例如。

    $.datepicker.formatDate('DD', new Date(2007, 1 - 1, 26));
    

    希望这会对您有所帮助。 UI/Datepicker/formatDate

    【讨论】:

    • 问题陈述目标 c 而 Iphone 不是 jquery
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-10
    • 2012-03-30
    相关资源
    最近更新 更多