For example, I want to get the numbers 12
and 34
from the time ** 12: 34 **.
I've found a lot of using DateFormatter
for the first time to get the date and time in Swift, but I couldn't (to me) cast it well because it was a string type.
The method I managed to find worked.
Calendar
let now = Date()
let time = Calendar.current.dateComponents([.hour, .minute], from: now)
print(time.hour!)
print(time.minute!)
I am vaguely wondering if I was spoiled by PHP. Even so, isn't it so troublesome to do such a simple thing? If there is an easy way, please let me know.
Recommended Posts