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

Categories

All i need to do is to change the way that xcode displaying my values in. My code currently displaying the age of something in minutes e.g 4503mint . I want to be able to display these values in the following format 3 days 3 hours 3 mint rather than 4503 mint. Really appreciate your help. Regards

See Question&Answers more detail:os

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

1 Answer

You said:

My code currently displaying the age of something in minutes e.g 4503mint . I want to be able to display these values in the following format 3 days 3 hours 3 mint rather than 4503 mint.

You can format this using NSDateComponentsFormatter. Just multiply the number of minutes by 60 to get the NSTimeInterval, and then you can supply that to the formatter:

let formatter = NSDateComponentsFormatter()
formatter.unitsStyle = .Full

let minutes = 4503
let timeInterval = NSTimeInterval(minutes * 60)
print(formatter.stringFromTimeInterval(timeInterval))

That will produce "3 days, 3 hours, 3 minutes" (or in whatever format appropriate for the locale for that device).

See NSDateComponentsFormatter Reference for more information.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...