Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift NSDate get current date but strip Year, Month, and Day

Tags:

swift

nsdate

I am trying to get the current date using swift. I have that taken care of but it gets the year month and day and I really only want the current hour and minute. The reason being is that I am trying to later on compare a created date that only has an hour and minute. I am currently just using this

let currentDate = NSDate()

Thank you


1 Answers

let calendar = Calendar.autoupdatingCurrent
let components = calendar.dateComponents([.hour, .minute], from: Date())
let hour = components.hour
let minute = components.minute
like image 197
rob mayoff Avatar answered Dec 02 '25 16:12

rob mayoff



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!