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

I have a number of X days, let's say 700. How can I output this 700 to years? Eg. 700 = 1.11 years (1 year 11 months) or 2.2 (2 years and two months) ... And so on

I don't care for leap years or such, just need an aproximate value.

See Question&Answers more detail:os

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

1 Answer

Think about it...

700 days, 30 days in a month.

700/30 = 23.33 months. 12 months in a year.

23.33/12 = 1.944444... take the integer value (int)1.944444 to get 1 for the year.

23.33%12= 11.33... months. You can cast it to an int as well to get 11

Your result: 1 year, 11 months


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