Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

Any C#fags around here?

Name: Anonymous 2010-02-01 17:40

I just have a quick question about calculating a timespan of sorts.

Basically I have two variables:

int depart = 0930;
int arrive = 1545;

where both are integers representing military time.

Is there a simple way to get a return value based on those integers which gives me a timespan in minutes? In the end, I need to get two separate values for hours and minutes, but I can just divide and mod the total minutes by 60 for those values.

I'm pretty new to C# and I know it has DateTime and TimeSpan stuff predefined and I'm hoping that there's a simple way to use one of those for what I need as opposed to writing an entire method from scratch

Name: Anonymous 2010-02-01 20:38

Shouldn't this be in /prog/?
Although they'd just tell you to read your SICP.

Name: Anonymous 2010-02-01 20:54

writing an entire method from scratch


int mil2min(int mil) {
  int min = mil % 100;
  int hour = mil / 100;
  min += mil * 60;
  return min
}

WAS THAT SO HARD?

Name: Anonymous 2010-02-01 21:11

er, hour*60

Name: Anonymous 2010-02-02 0:57

If you're set on using the DateTime class it's a bit more tedious than >>3. You're going to need a constructor class for creating a DateTime class from military time.


public static class MilitaryTimeConstructor
{
    public static DateTime Parse(int time)
    {
        return new DateTime(1, 1, 1, time / 100, time % 100, 0);
    }
}


To get the minutes from that class you need to add up the hours * 60 + the minutes.

Name: Anonymous 2010-02-02 22:20

appending "fag" at the end of a term
Back to the imageboards, please.

Don't change these.
Name: Email:
Entire Thread Thread List