Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / November 2006

Tip: Looking for answers? Try searching our database.

Simple question

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
D. Yates - 20 Nov 2006 16:41 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.