简体   繁体   English

C#比较日期时间为每月的某天和时间

[英]c# compare datetime for day of month and time

I need to compare two datetime variable only for some criteria : Day of the month and time . 我仅需要针对某些条件比较两个datetime变量:月中的某天和时间。

If the day of the month and the time is equal to another datetime then the expression return true, the comparison must not keep in mind of the month and the year of the two Datetime . 如果月份中的日期和时间等于另一个datetime,则表达式返回true,则比较时必须牢记两个Datetime的月份和年份。

What's the best way to do this comparison ? 进行此比较的最佳方法是什么?

Thanks. 谢谢。

Compare the Day and the TimeOfDay properties of the two DateTime values: 比较两个DateTime值的DayTimeOfDay属性:

bool areEqual = (d1.Day == d2.Day)
             && (Math.Abs((d1.TimeOfDay - d2.TimeOfDay).TotalSeconds) < 1.0);

Adjust for different time zones before comparing if necessary. 如有必要,请在不同时区进行调整。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用年月日和时间在c#中转换DateTime - Convert DateTime in c# using year month day and time 如何在c#中使用DateTime获取下个月的同一时间和日期 - How to get the same time and Day next month using DateTime in c# 在 C# 中将带有未知分隔符和可选时间元素的年/月/日字符串解析为 DateTime - Parse year/month/day string with unknown dividers and optional time element into a DateTime, in C# C#中年,月和日参数的不可表示的DateTime - An un-representable DateTime for year, Month and Day parameters in C# 如何在C#中的DateTime中指定日期和月份而不是年份 - how to specify day and month but not the year in DateTime in c# C#日期时间格式,包括日期/月/年而非日期 - C# datetime format that includes date/month/year and not day 如何在 C# 中将 DATETIME 列值划分为日、月和年 - How to divide DATETIME column value into day, month and year in C# 将datagridview中的日期列与日期时间的月份进行比较 c# winform - Compare the date column in datagridview with month of datetime c# winform 什么是C#最简单的方法来定义一天中的时间,即HH:MM:SS,而不是求助于需要年,月,日的DateTime? - Whats the easiest way in C# to define a time of day, i.e. HH:MM:SS, without resorting to DateTime which requires year,month,day? 如何在C#中使用日期时间获取月份的第一天和月份的最后一天 - how to get first day of month and last day of month using date time in C#
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM