Simple question

  • Thread starter Thread starter D. Yates
  • Start date Start date
D

D. Yates

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.....if I could find them.....

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

Thanks,
Dave
 
TimeSpan has the TicksPerWhatever constants, but no; you may need to add
your own constants if you value this...

Marc
 
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.Globalization.CultureInfo.CurrentCulture 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.
 
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.FromDays(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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top