| View previous topic :: View next topic |
| Author |
Message |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Wed Oct 04, 2006 7:07 pm Post subject: [Help] Calculate time [Solved] |
|
|
hi there.
i need to know if there are any kind of way to calculate the time since i've added something that i'm searching for and the time when i trigger a certain command.
[23:54:41] (@w00f) !adefine w00f test!
[23:54:43] (@w00f) !define w00f
[23:54:44] (@b0T) w00f: test! :: added at 10/04/06 23:54:41
what i want is to convert that time (10/04/06 23:54:41 , i save the time when i add the definition) to something like this:
[23:54:44] (@b0T) w00f: test! :: added 3s ago.
a month later
[23:54:44] (@b0T) w00f: test! :: added 1m 3s ago.
or
[23:54:44] (@b0T) w00f: test! :: added 4w 3s ago.
or 4w 0d 0h 0m 3s ago
something like that would be great.
tnks in advance.
Last edited by w00f on Sat Oct 21, 2006 5:08 pm; edited 1 time in total |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Wed Oct 04, 2006 11:14 pm Post subject: |
|
|
Convert the time to EPOCH time, with clock scan:
set mytime [clock scan "10/04/06 23:54:41"]
set nowtime [clock scan [strftime "%m/%d/%y %T"]]
then use the 'duration' command to diff the times:
set difftime [duration [expr $nowtime - $mytime]]
Hmm now that I look at my date.tcl script, you can simplify the difftime by just using [unixtime] to get the current time:
set difftime [duration [expr [unixtime] - $mytime]]
The date.tcl script I (re)did has a whole lot of examples of manipulating dates/times and checking for leap years and valid input, reading/writing to files, and so forth and so on. It's in the tcl archive if you want to look at it. |
|
| Back to top |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Thu Oct 05, 2006 1:42 pm Post subject: |
|
|
Thanks man , works great.
i'll take a look at date.tcl , could be usefull ;D |
|
| Back to top |
|
 |
metroid Owner
Joined: 16 Jun 2004 Posts: 771
|
Posted: Fri Oct 06, 2006 1:45 am Post subject: |
|
|
Sorry but why would you use clock scan on the current time if [clock seconds] or [unixtime] is available?
That just seems like you're making TCL do something that it doesn't have to. |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Fri Oct 06, 2006 2:51 am Post subject: |
|
|
| rosc2112 wrote: |
Hmm now that I look at my date.tcl script, you can simplify the difftime by just using [unixtime] to get the current time:
set difftime [duration [expr [unixtime] - $mytime]]
|
|
|
| Back to top |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Sun Oct 08, 2006 11:27 am Post subject: |
|
|
I've started to play with dates and stuff like that but in one the codes i've got a problem...i saw date.tcl but i was a little confused about how i can convert a date(10/01/06 09:20 for example[month/day/year Hours:minutes) to "clock second" format.
i've tried some codes but none of them seems to work as i want.
need help =X |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Oct 08, 2006 6:59 pm Post subject: |
|
|
clock seconds
Return the current date and time as a system-dependent integer value. The unit of the value is seconds, allowing it to be used for relative time calculations. The value is usually defined as total elapsed time from an ``epoch''. You shouldn't assume the value of the epoch.
So the [clock seconds] command will produce the current EPOCH time:
set now [clock seconds]
If you're wanting to convert a specific date and time into the EPOCH time, you use:
set mytime [clock scan "10/04/06 23:54:41"]
check the clock manpage for the formats for the date, the command is particular about the format (eg, month day,<comma required> year <time format>)
Date:
The acceptable formats are
mm/dd/yy (10/08/06)
monthname dd, yy (october 08, 06 or october 08, 2006)
dd monthname yy (08 october 06 or 08 october 2006)
day, dd monthname yy (sun, 08 october 06)
CCyymmdd (20061008 or 061008 )
CCyy-mm-dd (2006-10-08 or 06-10-08 )
dd-monthname-CCyy (08-october-2006 or 08-october-06)
The default year is the current year. If the year is less than 100, we
treat the years 00-68 as 2000-2068 and the years 69-99 as 1969-1999. Not all platforms can represent the years 38-70, so an error may result if these years are used.
Time:
A time of day, which is of the form:
hh:mm:ss
meridian zone
hhmm meridian zone
If no meridian is specified, hh is interpreted on a 24-hour clock.
Also note that the date/time have to be within double-quotes " " |
|
| Back to top |
|
 |
w00f Halfop
Joined: 04 Oct 2006 Posts: 49
|
Posted: Mon Oct 09, 2006 5:32 pm Post subject: |
|
|
tnks man (one more time)
I have everything to work now.
u've been a great help ;D |
|
| Back to top |
|
 |
|