c# - for 循环的问题,并尝试将列表声明从列表字符串到日期时间的转换中分离出来
问题描述
因此,我正在尝试制作一个“PTO 计算器”,它将计算一年中剩余工作日的百分比与我剩余的 PTO 工作时间百分比。基本上,我可以使用一个应用程序来快速查看我是否在整个一年中过快地消耗了分配的带薪休假。这是我到目前为止所拥有的,
using System;
using System.Globalization;
using System.Linq;
class Program
{
static void Main()
{
int PTOHoursTotal = 144;
int PTOleft = 91;//user inputs the number of PTO hours remaining
int workdays = 366;//the for loop below will run through the entire year and deduct
//holidays and weekends from 366 to give the total number of workdays in the year
var Holidays = new[]
{
"February 17, 2020", "May 25, 2020",
"July 3, 2020", "September 7, 2020",
"October 12, 2020", "November 11, 2020",
"November 26, 2020", "December 25, 2020"
}.Select(str => DateTime.ParseExact(str, "MMMM d, yyyy", CultureInfo.InvariantCulture));
for (DateTime i = DateTime(2020, 1, 1); i < (2020, 12, 31); i.AddDays(1))
{
if (Holidays.Contains(i) || i.DayOfWeek == Saturday || i.DayOfWeek == Sunday)
{
workdays--;
}
Console.WriteLine(workdays);
}
}
我相当肯定我的 for 循环有问题,最重要的是,如果有人可以展示一种方法,将声明的假日字符串列表从字符串转换为日期时间拆分,那将不胜感激。根据某个日期计算网站,最终的工作日数应该是 251。
解决方案
推荐阅读
- html - SQL:读取查询返回的 span HTML 元素内的文本
- elasticsearch - 为 elasticsearch 索引模板设置动态模板属性时可以使用通配符吗?
- amazon-web-services - 如何从 AWS-Task 获取 Docker ID 并将其登录到 SpringBoot 应用程序?
- scala - Databricks SparkException 超过 spark.driver.maxResultSize
- java - 身份验证后的 Spring 调用控制器
- regex - 正则表达式匹配 JSON 列表中的特定键
- python - 有没有办法用 Folium 增加 18 层以上的缩放?
- javascript - 按另一个数组中的项目过滤javascript数组映射?
- bash - 如何在bash中将另一个变量附加到变量的每一行?
- spring-boot - @AutoConfigureMockMvc 如何设置消息转换器