Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
422 views
in Technique[技术] by (71.8m points)

nsdate - Check if date is before current date (Swift)

I would like to check if a NSDate is before (in the past) by comparing it to the current date. How would I do this?

Thanks

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

I find the earlierDate method.

if date1.earlierDate(date2).isEqualToDate(date1)  {
     print("date1 is earlier than date2")
}

You also have the laterDate method.

Swift 3 to swift 5:

if date1 < date2  {
     print("date1 is earlier than date2")
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...