简体   繁体   中英

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)

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

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM