【问题标题】:Selecting date in celander is giving me previous date using Vurig-Calendar Library in iOS在 celander 中选择日期是在 iOS 中使用 Vurig-Calendar 库给我上一个日期
【发布时间】:2013-02-25 10:49:28
【问题描述】:

我已经下载了这个库https://github.com/TjeerdVurig/Vurig-Calendar。现在我面临的问题是,例如,如果我选择 2013 年 2 月 25 日,它会打印 2013 年 2 月 24 日。我在代码中找不到任何东西。是因为时区还是与编码无关的原因? 请指教

谢谢

【问题讨论】:

    标签: ios objective-c nscalendar


    【解决方案1】:

    你的时区有问题,可以通过添加这行代码来解决:

    [格式化程序 setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];

    更新

    1. Question 1

    2. Question 2

    3. Question 3

    【讨论】:

    • 感谢您的帮助,但即使粘贴此代码后,我仍然遇到同样的问题。
    • 只玩 GMT 可能对你有帮助
    • 尝试了以上所有建议仍然不起作用..谢谢
    • 感谢伙伴,所有三个链接都非常有帮助,而且切中要害。学到了很多谢谢。
    • 你一开始是对的,而不是 NSDateFormatter 的 TimeZone 我只需要更改 NSDateComponents timeZone.[components setTimeZone:[NSTimeZone timeZoneWithName:@"GMT"]];而不是它的工作正常。再次感谢
    【解决方案2】:

    这很容易做到。在您的VRGCalendarView.m 中转到方法

    - (void)drawRect:(CGRect)rect {
        int firstWeekDay = [self.currentMonth firstWeekDayInMonth]-1;
    }
    

    把这个改成:

    int firstWeekDay = [self.currentMonth firstWeekDayInMonth];
    

    int selectedDateBlock = ([selectedDate day]-1)+firstWeekDay;
    

    把这个改成

    int selectedDateBlock = ([selectedDate day]-2)+firstWeekDay;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-06
      • 1970-01-01
      • 1970-01-01
      • 2019-06-30
      • 1970-01-01
      • 2014-02-19
      • 2021-07-28
      相关资源
      最近更新 更多