Public Class TimeHelpers ''' ''' Converts an amount of seconds to a TimeSpan. ''' ''' The seconds to convert. Public Shared Function ConvertSecondToTime(ByVal Seconds As Integer) As TimeSpan Dim minutes As Integer = 0 Dim hours As Integer = 0 While Seconds > 60 minutes += 1 Seconds -= 60 If minutes > 60 Then minutes = 0 hours += 1 End If End While Dim reSpan As New TimeSpan(hours, minutes, Seconds) Return reSpan End Function ''' ''' Returns the amount of time the player has played. ''' Public Shared Function GetCurrentPlayTime() As TimeSpan Dim PTime As TimeSpan = Core.Player.PlayTime Dim diff As TimeSpan = (Date.Now - Core.Player.GameStart) PTime += diff Return PTime End Function ''' ''' Returns the time to display as string. ''' ''' The DateTime to display. ''' To show the seconds or not. Public Shared Function GetDisplayTime(ByVal DateTime As Date, ByVal ShowSeconds As Boolean) As String Return GetDisplayTime(New TimeSpan(DateTime.Hour, DateTime.Minute, DateTime.Second), ShowSeconds) End Function ''' ''' Returns the time to display as string. ''' ''' The TimeSpan to display. ''' To show the seconds or not. Public Shared Function GetDisplayTime(ByVal Time As TimeSpan, ByVal ShowSeconds As Boolean) As String Dim days As Integer = Time.Days Dim hour As Integer = Time.Hours If days > 0 Then hour += days * 24 End If Dim hours As String = hour.ToString() If hours.Length = 1 Then hours = "0" & hours End If Dim minutes As String = Time.Minutes.ToString() If minutes.Length = 1 Then minutes = "0" & minutes End If Dim seconds As String = Time.Seconds.ToString() If seconds.Length = 1 Then seconds = "0" & seconds End If Dim t As String = hours & ":" & minutes If ShowSeconds = True Then t &= "." & seconds End If Return t End Function End Class