ServUO Version
Publish 57
Ultima Expansion
Endless Journey
So rummaging through old posts as I normally do I stumbled across this:
Shows the game time in days under the player, the first post shows actual account age.

My question is how can I cleanly format it to show Years, Months, Days, Hours. I figured out probably a very dirty way to show years using the following:
C#:
list.Add(1060658, String.Format("Age\t{0} Years", (totalTime.Days/365).ToString())); // ~1_val~: ~2_val~
100% sure there is a better way to do this but I'm no coder so thought I would post to ask :)



After further refinement I came up with this which again can probably be improved haha:
C#:
list.Add(1060658, String.Format("Age\t{0} Years {1} Days {2} Hours", (totalTime.Days/365).ToString(), (totalTime.Days - ((totalTime.Days / 365)*365)).ToString(), totalTime.Hours.ToString())); // ~1_val~: ~2_val~



and after further further refinement this is what I came up with for my final result...
C#:
                TimeSpan totalTime = (DateTime.UtcNow - acct.Created);
                if (totalTime.Days > 365)
                {
                    if (acct != null && AccessLevel <= AccessLevel.Player)
                    {
                        list.Add(1060658, String.Format("Age\t{0} Years {1} Days {2} Hours", (totalTime.Days / 365).ToString(), (totalTime.Days - ((totalTime.Days / 365) * 365)).ToString(), totalTime.Hours.ToString())); // ~1_val~: ~2_val~
                    }
                }
                else
                {
                    if (acct != null && AccessLevel <= AccessLevel.Player)
                    {
                        list.Add(1060658, String.Format("Age\t{0} Days {1} Hours", totalTime.Days.ToString(), totalTime.Hours.ToString())); // ~1_val~: ~2_val~
                    }
                }
                if (GameTime.Days > 365)
                {
                    if (acct != null && AccessLevel <= AccessLevel.Player)
                    {
                        list.Add(1060658, String.Format("Gametime\t{0} Years {1} Days {2} Hours", (GameTime.Days / 365).ToString(), (GameTime.Days - ((GameTime.Days / 365) * 365)).ToString(), GameTime.Hours.ToString())); // ~1_val~: ~2_val~
                    }
                }
                else
                {
                    if (acct != null && AccessLevel <= AccessLevel.Player)
                    {
                        list.Add(1060658, String.Format("Gametime\t{0} Days {1} Hours", GameTime.Days.ToString(), GameTime.Hours.ToString())); // ~1_val~: ~2_val~
                    }
                }
 
Last edited:
Back