Simple question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • D. Yates

    Simple question

    Hi all,

    Is there a place in the .NET framework where simple time constants are
    defined?

    For example:
    How many days are there in a week? Hours in a day? Minutes in an hour?
    Seconds in a minute?

    None of these are going to change, so they are obviously constants. Now I
    can define my own constants, but it would be just as easy to use the
    frameworks constants.....i f I could find them.....

    The logical place to look was System.DateTime .DaysInOneWeek; however, this
    does not exist.

    Thanks,
    Dave


  • Marc Gravell

    #2
    Re: Simple question

    TimeSpan has the TicksPerWhateve r constants, but no; you may need to add
    your own constants if you value this...

    Marc


    Comment

    • Dave Sexton

      #3
      Re: Simple question

      Hi Dave,

      The problem is that they may change depending on the locale of the computer running the code.
      Calendars vary from culture to culture, and so I assume time constants may as well.

      The type of information you have requested would normally be found in the
      System.Globaliz ation.CultureIn fo.CurrentCultu re object, however I couldn't find any properties or
      methods that seem to apply. Take a look and maybe you'll have better luck than I have.

      --
      Dave Sexton

      "D. Yates" <foeman@hotmail .comwrote in message news:%23sQR2LMD HHA.4928@TK2MSF TNGP02.phx.gbl. ..
      Hi all,
      >
      Is there a place in the .NET framework where simple time constants are defined?
      >
      For example:
      How many days are there in a week? Hours in a day? Minutes in an hour? Seconds in a minute?
      >
      None of these are going to change, so they are obviously constants. Now I can define my own
      constants, but it would be just as easy to use the frameworks constants.....i f I could find
      them.....
      >
      The logical place to look was System.DateTime .DaysInOneWeek; however, this does not exist.
      >
      Thanks,
      Dave
      >

      Comment

      • Rad [Visual C# MVP]

        #4
        Re: Simple question

        I think it'd save you time to define them yourself in a central enum
        ....

        On Mon, 20 Nov 2006 10:41:48 -0600, "D. Yates" <foeman@hotmail .com>
        wrote:
        >Hi all,
        >
        >Is there a place in the .NET framework where simple time constants are
        >defined?
        >
        >For example:
        >How many days are there in a week? Hours in a day? Minutes in an hour?
        >Seconds in a minute?
        >
        >None of these are going to change, so they are obviously constants. Now I
        >can define my own constants, but it would be just as easy to use the
        >frameworks constants.....i f I could find them.....
        >
        >The logical place to look was System.DateTime .DaysInOneWeek; however, this
        >does not exist.
        >
        >Thanks,
        >Dave
        >
        --

        Bits.Bytes.

        Comment

        • Fred Mellender

          #5
          Re: Simple question

          You might find that you can obtain these constants via TimeSpan. E.G.

          static int hoursInDay = (new TimeSpan(1,0,0, 0)).Hours; or
          TimeSpan.FromDa ys(1.0).Hours;

          and similar techniques. Or, it may be you need these constants only in the
          context of figuring a time span or a date, in which case it would be better
          to use DateTime and/or TimeSpan directly.

          "D. Yates" <foeman@hotmail .comwrote in message
          news:%23sQR2LMD HHA.4928@TK2MSF TNGP02.phx.gbl. ..
          Hi all,
          >
          Is there a place in the .NET framework where simple time constants are
          defined?
          >
          For example:
          How many days are there in a week? Hours in a day? Minutes in an hour?
          Seconds in a minute?
          >
          None of these are going to change, so they are obviously constants. Now I
          can define my own constants, but it would be just as easy to use the
          frameworks constants.....i f I could find them.....
          >
          The logical place to look was System.DateTime .DaysInOneWeek; however, this
          does not exist.
          >
          Thanks,
          Dave
          >

          Comment

          Working...