【问题标题】:How to check a Persian date between two Persian dates?如何检查两个波斯日期之间的波斯日期?
【发布时间】:2021-03-30 16:57:58
【问题描述】:

我的波斯日期格式可以采用以下格式之一:mm/YYYY 或 YYYY/mm 没有日期信息,只有年和月。 我想检查两个波斯日期之间的波斯日期: 例如,1400/01 介于 1399/07 和 1400/03 之间 当日信息不可用时,我该怎么做?

【问题讨论】:

    标签: c# date farsi


    【解决方案1】:
     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();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-10-05
      • 1970-01-01
      • 2018-12-14
      • 2023-03-30
      • 1970-01-01
      • 1970-01-01
      • 2015-12-24
      • 2021-12-03
      相关资源
      最近更新 更多