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
439 views
in Technique[技术] by (71.8m points)

ios - how to get today's date less 18 years

What is the correct way to get date of 18 years ago from today's Date in Swift3?

In Swift2, I had

let startingDate = NSDate(timeIntervalSinceNow: -600000000)
See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

If you want date with 18 year less you can use Calendar unit year for that.

let date = Calendar.current.date(byAdding: .year, value: -18, to: Date())

Output

enter image description here


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

...