Computer Science Canada defining time |
Author: | iluvchairs112 [ Mon Aug 18, 2008 8:13 pm ] |
Post subject: | defining time |
is it possible to definine a variable using a unit of time? ex. minutes, seconds, miliseconds? so that it is entered 1.22.89 thanks ![]() |
Author: | CodeMonkey2000 [ Mon Aug 18, 2008 9:23 pm ] |
Post subject: | RE:defining time |
I'm not sure what you mean. You could define a class or structure Time, if that' what you mean. |
Author: | Tony [ Mon Aug 18, 2008 11:14 pm ] |
Post subject: | RE:defining time |
Well time is interpreted (depending on where you get it from) as a number of seconds as either an integer or a float-point number. |
Author: | btiffin [ Tue Aug 19, 2008 2:15 am ] | ||
Post subject: | RE:defining time | ||
Use REBOL ![]()
One of the few languages I know of with a time! and date! datatype. Excuse the interruption to the Turing forum. Cheers |
Author: | DemonWasp [ Tue Aug 19, 2008 8:27 am ] |
Post subject: | RE:defining time |
Erm...don't most languages have either Date and Time classes or something like a DateTime? Java, C# and Javascript certainly do, and as I recall, C++ has about 7 of each (because that's how C++ rolls). |
Author: | SNIPERDUDE [ Tue Aug 19, 2008 9:26 am ] |
Post subject: | RE:defining time |
lol. The language I've been meaning to learn for a good while now... Already know Turing, Java, VB, HTML. But on topic: Yea, turing should have a built in time function, look it up on help. |
Author: | iluvchairs112 [ Tue Aug 19, 2008 9:27 am ] |
Post subject: | RE:defining time |
I know time is measured in seconds and I could just use integers. However that will take a lot longer. What I want to do is get a certain amount of times from the user and sort them from least time to most time. |
Author: | DemonWasp [ Tue Aug 19, 2008 9:40 am ] |
Post subject: | RE:defining time |
Well, you could do it the right way, or the cheap way. The Right Way: Parse the input you're given (hours.minutes.seconds?) and convert entirely to seconds or somesuch. Store that information and use those to do the sorts. Have a function that outputs the time corresponding to that number. The Cheap Way: Make sure all your input is in the form like the following: 08.06.15 (for 8 hours, 6 minutes, 15 seconds) 12.52.01 (for 12 hours, 52 minutes, 1 second) Then you can just use string-based comparisons to sort them into their overall order. The leading zeros are important so that the digits with the same magnitude are being compared. I'd do the Right Way myself, since it's actually probably easier and is guaranteed to work better (don't need any funny leading zeros or other nonsense). |
Author: | iluvchairs112 [ Tue Aug 19, 2008 9:50 am ] |
Post subject: | RE:defining time |
Thanks. Why I didn't think of "The Right Way" myself, I don't know ![]() That is how I will do it ... that actually makes everything a whole lot easier. I was overthinking it all :S |