- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
如何获得基于给定日期的月份的实际日期?例如,我想检索2017年6月的所有日期,即星期六。我该如何实现?样例代码将不胜感激,因为我为此奋斗了几天。
最佳答案
DateComponents
具有weekday
属性,代表星期几。在基金会的公历中,工作日为1,星期日为2,星期一为…,星期六为7。DateComponents
也具有weekdayOrdinal
属性,表示“the position of the weekday within the next larger calendar unit, such as the month. For example, 2 is the weekday ordinal unit for the second Friday of the month.”
因此,让我们在2017年6月的某个星期六初始化DateComponents
。如果您不在乎时间,通常最好指定中午时间,因为midnight (the default time of day) can cause problems in some time zones on some days。
var components = DateComponents(era: 1, year: 2017, month: 06, hour: 12, weekday: 7)
var calendar = Calendar.autoupdatingCurrent
for i in 1 ... 5 {
components.weekdayOrdinal = i
let date = calendar.date(from: components)!
let ymd = calendar.dateComponents([.year, .month, .day], from: date)
guard ymd.month == components.month else { break }
print("\(ymd.year!)-\(ymd.month!)-\(ymd.day!)")
}
2017-6-3
2017-6-10
2017-6-17
2017-6-24
NSDateComponents *components = [NSDateComponents new];
components.era = 1;
components.year = 2017;
components.month = 6;
components.hour = 12;
components.weekday = 7;
NSCalendar *calendar = NSCalendar.autoupdatingCurrentCalendar;
for (NSInteger i = 1; i <= 5; ++i) {
components.weekdayOrdinal = i;
NSDate *date = [calendar dateFromComponents:components];
NSDateComponents *ymd = [calendar components:NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay fromDate:date];
if (ymd.month != components.month) { break; }
NSLog(@"%ld-%ld-%ld", (long)ymd.year, (long)ymd.month, (long)ymd.day);
}
关于ios - 如何获得一个月中特定工作日的所有天数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44600192/
我正在尝试创建一个脚本,该脚本在设定的时间段(上个月的 23 日和本月的 23 日)内获取工作日、日历日和工作日的计数。 我有以下脚本,我尝试使用 Worksheet Functions 但它不起作用
如何将 xts 对象子集以仅包含工作日(周一至周五,周六和周日除外)? 最佳答案 这是我要做的: library(xts) data(sample_matrix) sample.xts <- as.x
我一直在尝试计算在特定工作日内创建了多少个值没有成功: SELECT count(*) as count FROM packets WHERE strftime("%w", timeIn) = '1'
我正在编写一个脚本,它只在周一至周五上午 8 点至下午 5 点期间运行。问题是在它脱离 8-5 或 M-F while() 循环之后,它只是......不知道如何回到循环中。这让我觉得我可能以错误的角
我想得到上一季度的最后一个工作日(工作日),比如 2019.03.31 是星期天,所以我的要求是得到 2019.03.29 的输出。 我写了下面的代码,它工作得很好但看起来不整洁,在我看来 kdb 有
我想知道我在这个网格中选择日期时的工作日。我尝试了有效的 JavaScript 代码,但在 C# 中使用它时遇到了一些困难。 string startdate, enddate;
如标题所示,我正在为我的应用程序寻找解决方案,包括在工作日添加开放和关闭时间。 图像我的应用程序: View list days of the week View after selecting th
SELECT * FROM (`users`) JOIN `artistprofiles` AS art ON `art`.`user_id` = `users`.`id` WHE
我需要将这个函数翻译成swift。基本上它得到了本周的“n”日是什么。因此,例如,如果我将它与 NSDate().getWeekDay(0) 一起使用,它会给我 9 月 11 日星期日,依此类推。但似
我是工作日 SOAP API 的新手,我正在尝试弄清楚如何发送 SOAP 请求以使用 SOAPUI 进行身份验证。 任何建议将不胜感激。 最佳答案 Workday API 使用 WS-Security
我面临以下问题:我必须将当前日期与给定工作日和时间的特定时间点进行比较,如下所示: const myObj = { "weekday": "Tuesday", "timeOfDay": "10
我之前已经发布过相关内容,这有助于我获得以下 SQL: SELECT fname, MONTH( eventDate ) , IF( WEEKDAY( eventDate ) = 5,1,0)) A
尝试使用 moment.js 获得第二个星期四(例如)。本周四不。下一个。 2 个星期四内的日期。 我已经尝试过 moment().add(1, 'week').day(4) 仅获取下周的星期四(仅当
现在是 2017 年 10 月 8 日,星期日。 var weekday = Calendar(identifier: .iso8601).component(.weekday, from: Date
关闭。这个问题需要更多focused .它目前不接受答案。 想改进这个问题吗? 更新问题,使其只关注一个问题 editing this post . 关闭 6 年前。 Improve this qu
我们使用以下规则来标记延迟 2 天或更长时间的工作项: Changed Date , > , = , [Field], >[Field], =[Field], <=[Field], In, No
我有平日 jQuery UI 选项卡,如下所示,我想在当前工作日打开它们: Monday Tuesday Wednesday Thursday Friday
我想找到一周中某一天到一周中另一天的相对距离。假设以下 R 输入是从第 0 天开始的相对差异(以天为单位): day pmin( day %% 7, rev(day)%%7) [1] 0 1 2
我一直在寻找下个月第一,第二,第三或第四工作日(工作日)的日期。 我有以下代码: NSTimeInterval *lastDue; // unix time stamp from last due d
有一个 pandas 数据框 df,为了从日期列中获取工作日,我做了: df_raw['DayOfWeek'] = df_raw[str_date_colname].dt.strftime('%w')
我是一名优秀的程序员,十分优秀!