• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 362
  • Last Modified:

How do I convert an integer into time string?

I'm looking for a clear, simple solution to take and integer and turn it into time. i.e. 7 = "0:07"; 61 = "1:01" etc. Just looking for some sample code to do this.
Michael Sterling
Michael Sterling
1 Solution
int timeNumber = 61;
DateTime time = DateTime.ParseExact(timeNumber.ToString().PadLeft(6, '0'), "HHmmss", null);
käµfm³d 👽Commented:

static void Main(string[] args)
    int x = 7;
    TimeSpan t = TimeSpan.FromMinutes(x);


    x = 61;
    t = TimeSpan.FromMinutes(x);


Open in new window

Michael SterlingWeb Applications DeveloperAuthor Commented:
@ rusty: When i try to assign to the datetime variable i get:

The DateTime represented by the string is not supported in calendar Systme.Globalization.GregorianCalendar."

Michael SterlingWeb Applications DeveloperAuthor Commented:
that worked! thank you!
John (Yiannis) ToutountzoglouInstructor Multiengine PilotCommented:
hi ...simply
Private Function MinutesToTime(ByVal dMinutes As Double) _
As String
        MinutesToTime = Format(DateAdd("n", dMinutes, "00:00"), "HH:mm")
    End Function

Open in new window

65 -> 1:05
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now