如何确定NSDate是否是工作日? [英] How can I find out whether an NSDate is a business day?

查看:101
本文介绍了如何确定NSDate是否是工作日?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何确定NSDate是否是工作日?也就是说,根据用户当前的语言环境和日历设置,是否是周末-而不是硬编码为星期一到星期五?

How can I find out whether an NSDate is a business day? That is to say, whether or not it is a weekend according to the user's current locale and calendar settings - so not hardcoded to just be Monday to Friday?

NSCalendar具有一个firstWeekday属性,但这似乎只是一个呈现性的东西.在美国是星期日,在英国是星期一.

NSCalendar has a firstWeekday property, but that just seems to be a presentational thing; it's Sunday in the US and Monday in the UK.

我不担心假期,我只想能够以与内置日历应用程序相同的方式来遮挡日历的周末.

I'm not worried about holidays, I just want to be able to shade the weekends of a calendar in the same way as the built-in calendar app.

推荐答案

iOS 8及更高版本的更新:

NSCalendar现在包含方法检查特定日历中日期是否在周末&区域设置.

which checks whether a date falls under weekend in a particular calendar & locale.

旧答案

如果您只需要在周末遮荫,则[NSDateComponents weekday]是您的朋友.此方法将在星期日返回1,在星期六返回7.

If you only need to shade the weekends, [NSDateComponents weekday] is your friend. This method will return 1 for Sunday and 7 for Saturday.

事实:大多数申请都假设周末=星期六& ;;星期日. AFAIK这对于使用公历的所有国家都是正确的.涵盖所有其他日历的唯一可能性是每个日历/区域设置一个本地数据库,并注意更改.如果发生此类更改,则需要更新应用程序或必须下载新数据.

Fact: Most applications assume weekend = Saturday & Sunday. AFAIK this is correct for all countries using Gregorian Calendar. The only possibility covering all other calendars is to have a local database per calendar/locale and watch for changes. If such a change happens an application update is needed or new data has to be downloaded.

如果我们谈论的是工作日(不仅是周末),那么我们谈论的是

If we are talking about business days (not only weekends), we are talking about something that

  1. 没有明确的定义(公司之间的工作日之间发生什么变化)
  2. 没有规范(例如-日期格式,时区等具有国际公认的规范)
  3. 通常会根据当地法律进行更改(例如添加假期)

您需要的是让用户根据自己的国籍和雇主来为其个人需求设置您的应用程序.

What you need is to let the users set up your applications for their individual needs, depending on their nationality and employer.

这篇关于如何确定NSDate是否是工作日?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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