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
Marc Gravell - 20 Nov 2006 16:54 GMT
TimeSpan has the TicksPerWhatever constants, but no; you may need to add
your own constants if you value this...
Marc
Dave Sexton - 20 Nov 2006 16:59 GMT
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.

Signature
Dave Sexton
> Hi all,
>
[quoted text clipped - 11 lines]
> Thanks,
> Dave
Rad [Visual C# MVP] - 20 Nov 2006 17:14 GMT
I think it'd save you time to define them yourself in a central enum
...
>Hi all,
>
[quoted text clipped - 14 lines]
>Thanks,
>Dave
--
Bits.Bytes.
http://bytes.thinkersroom.com
Fred Mellender - 20 Nov 2006 17:27 GMT
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.
> Hi all,
>
[quoted text clipped - 14 lines]
> Thanks,
> Dave