Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Integer to Time Conversion

Integer to Time Conversion

Scheduled Pinned Locked Moved C#
tutorial
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lost User
    wrote on last edited by
    #1

    I need in a console application to have user input an integer in military time that be converted some how to 13:00 or 13:30 instead of 1330 the pure number.

    So that I can then take 1330 and have the user input an end time like 1430 and increase it by 25 percent to come out with 1445 or 2:45. So your increases the total time from 1 hour to 1 hour and 15 minutes.

    The input will always be HHMM in military time

    Simple Function is needed nothing advanced

    M P V 3 Replies Last reply
    0
    • L Lost User

      I need in a console application to have user input an integer in military time that be converted some how to 13:00 or 13:30 instead of 1330 the pure number.

      So that I can then take 1330 and have the user input an end time like 1430 and increase it by 25 percent to come out with 1445 or 2:45. So your increases the total time from 1 hour to 1 hour and 15 minutes.

      The input will always be HHMM in military time

      Simple Function is needed nothing advanced

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      So what have you written? You seem to have the wrong idea what this forum is for, we help budding developers improve their skills and learn, we do not supply solutions, that is your job. There are other sites that will supply the solution for a minimal payment, you may want to try there!

      Never underestimate the power of human stupidity RAH

      1 Reply Last reply
      0
      • L Lost User

        I need in a console application to have user input an integer in military time that be converted some how to 13:00 or 13:30 instead of 1330 the pure number.

        So that I can then take 1330 and have the user input an end time like 1430 and increase it by 25 percent to come out with 1445 or 2:45. So your increases the total time from 1 hour to 1 hour and 15 minutes.

        The input will always be HHMM in military time

        Simple Function is needed nothing advanced

        P Offline
        P Offline
        PIEBALDconsult
        wrote on last edited by
        #3

        I expect that one of the Parse methods of System.DateTime is all you need -- no integer is necessary. And why does this sound like homework? :~ "HHMM in military ISO 8601[^] time" FTFY

        L 1 Reply Last reply
        0
        • P PIEBALDconsult

          I expect that one of the Parse methods of System.DateTime is all you need -- no integer is necessary. And why does this sound like homework? :~ "HHMM in military ISO 8601[^] time" FTFY

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Your darn right its homework. Seeing as original thought doesn't exist and I have spent the better part of the day wrestling with this. I reached out to the community for insight.

          P 1 Reply Last reply
          0
          • L Lost User

            Your darn right its homework. Seeing as original thought doesn't exist and I have spent the better part of the day wrestling with this. I reached out to the community for insight.

            P Offline
            P Offline
            PIEBALDconsult
            wrote on last edited by
            #5

            If that's the better part I don't want to see the worse part. :-D

            1 Reply Last reply
            0
            • L Lost User

              I need in a console application to have user input an integer in military time that be converted some how to 13:00 or 13:30 instead of 1330 the pure number.

              So that I can then take 1330 and have the user input an end time like 1430 and increase it by 25 percent to come out with 1445 or 2:45. So your increases the total time from 1 hour to 1 hour and 15 minutes.

              The input will always be HHMM in military time

              Simple Function is needed nothing advanced

              V Offline
              V Offline
              VJ Reddy
              wrote on last edited by
              #6

              I think the following points may be helpful. Use DateTime.ParseExact to parse the time

              DateTime startTime = DateTime.ParseExact("1330","HHmm",
              System.Globalization.CultureInfo.InstalledUICulture);

              similarly parse the end time. Now find the duration between end time and start time using the Subtract method of DateTime object which returns a TimeSpan object. Then get the total minutes using the TotalMinutes method of TimeSpan object. Use the AddMinutes method of DateTime to add minutes to the end time Then get the string representation of modified end time using

              string endTimeString = endTime.ToString("HHmm",
              System.Globalization.CultureInfo.InvariantCulture);

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups