c# - 如何检查两个波斯日期之间的波斯日期?
问题描述
我的波斯日期格式可以采用以下格式之一:mm/YYYY 或 YYYY/mm 没有日期信息,只有年和月。我想检查两个波斯日期之间的波斯日期:例如,1400/01 介于 1399/07 和 1400/03 之间,当日信息不可用时如何执行此操作?
解决方案
public static DateTime GetDate(string initialValue)
{
int pos = initialValue.IndexOf("/");
string dformat = pos == 2 ? "MM/yyyy" : "yyyy/MM";
DateTime dDate = DateTime.MinValue;
DateTime.TryParseExact(initialValue, dformat, CultureInfo.GetCultureInfo("fa-IR"), DateTimeStyles.None, out dDate);
return dDate;
}
static void Main(string[] args)
{
string one = "1399/07";
string two = "03/1400";
string three = "01/1400";
DateTime dOne = GetDate(one);
DateTime dTwo = GetDate(two);
DateTime dThree = GetDate(three);
bool answer = dThree >= dOne && dThree <= dTwo;
Console.WriteLine($"'{dThree.ToString("yyyy-MM-dd")}' is between '{dOne.ToString("yyyy-MM-dd")}' and '{dTwo.ToString("yyyy-MM-dd")}'? => {answer}");
Console.ReadKey();
}
推荐阅读
- python - 设置 UTF-8 编码后未写入 CSV 文件的更改
- reactjs - 在 ReactJs 中单击外部时输入值消失
- python - `s = (iowa_file_data.dtypes == 'object')` 如何使`s` 成为`Series` 类型的变量
- alexa - 在 Alexa 中发送通知时如何在 Alexa 屏幕设备上不显示 ssml 标签
- sql - 使用更新/删除级联创建两个外键约束
- javascript - 如何在使用 jquery 刷新页面后保持复选框在模式中的选中状态?
- python - 如何在 R-markdown 的 html 输出中隐藏 matplotlib 给出的附加信息?
- json - Flutter 中 Rest API 的响应错误处理
- java - 不参与等式的总利息
- javascript - 根据匹配的属性合并两个对象数组