如何快速比较AM PM

时间:2018-10-26 06:39:12

标签: swift datetime

我几乎没有尝试,但是找不到如何比较上午和下午。

formatter.locale = Locale(identifier: "en_US_POSIX")
        formatter.dateFormat = "h:mm a"
        formatter.amSymbol = "AM"
        formatter.pmSymbol = "PM"
        dateString = formatter.string(from: Date())

        // date Format
        dateFormatter.timeStyle = DateFormatter.Style.none;
        dateFormatter.dateStyle = DateFormatter.Style.medium;
        currentDate = dateFormatter.string(from: now);

        if self.dateString >= "09:00 AM" { return true }

1 个答案:

答案 0 :(得分:2)

在iOS中,Apple提供了比较功能以与Date对象进行比较。 请找到下面的代码以比较时间

type
  PMyRec = ^TMyRec;
  TMyRec = record
    MyString : string;
    class operator Implicit(aRec : PMyRec) : TMyRec;
  end;
....
class operator TMyRec.Implicit(aRec : PMyRec) : TMyRec;
begin
  if aRec = nil then // to do something...
    raise Exception.Create('Possible bug is here!');
  Result.MyString := aRec^.MyString;
end;