如何在iOS swift中使用文本字段过滤日期数组?

时间:2017-10-17 05:26:55

标签: ios swift date filtering nsdatecomponents

我有两个文本域,其中包含" From Date"另一个包含"迄今为止"基于如何过滤日期数组。

1 个答案:

答案 0 :(得分:0)

您有两个日期首先是开始日期,其他日期是结束日期,另一个是在开始日期和结束日期之间检查的日期..

          let format = DateFormatter()
            format.dateFormat = "yyyy-MM-dd"// before formate 
             let date_selected = format.date(from: date)
            format.dateFormat = "dd-MM-yyyy"// change related to my format
           let seldate_selected = format.string(from: date_selected!)
            let dt = format.date(from: seldate_selected)
          let str_dat = format.date(from: startDate)
            let end_dat = format.date(from: endDate)

            if dt! >= str_dat! && dt! <= end_dat!
            {
              print("selected date is not in between start date and end date ")
           } 
         else 
          {
             print("selected date is not in between start date and end date ")
          }