| View previous topic :: View next topic |
| Author |
Message |
Access Voice
Joined: 04 Jun 2006 Posts: 22
|
Posted: Sun Dec 10, 2006 7:18 pm Post subject: Time problem... |
|
|
my code
| Code: | set mytime 2006-12-10 21:58:55
set unxtime [clock scan $mytime]
set now [unixtime]
set timeago [duration [expr ($now - $unxtime)]]
putchan $chan "mytime: $mytime timeago: $timeago |
my output
| Code: | | <eggdrop> mytime 2006-12-10 21:58:55 timeago: 5 weeks 1 day 5 hours 27 minutes 39 seconds |
how the code must be look to get following output?
| Code: | | <eggdrop> mytime 10.12.2006 21:58:55 timeago: 5w 1d 5h 27m(in) 39s(ec) |
THX |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Sun Dec 10, 2006 8:00 pm Post subject: |
|
|
| Code: |
set timeago [duration [expr ($now - $unxtime)]]
set week "";set day "";set hour ""';set min "";set sec ""
regexp {([0-9]) week.*? ([0-9]) day.*? ([0-9]) hour.*? ([0-9]) minute.*? ([0-9]) second.*?} $timeago week day hour min sec
putchan $chan "mytime $mytime: timeago: $week\w $day\d $hour\h $min\m $sec\s"
#antiwordwrap#--------------------------------------------------------------------------------------------------------------
|
That's one way. |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Mon Dec 11, 2006 8:15 am Post subject: |
|
|
| rosc2112 wrote: | | Code: | | regexp {([0-9]) week.*? ([0-9]) day.*? ([0-9]) hour.*? ([0-9]) minute.*? ([0-9]) second.*?} $timeago week day hour min sec |
|
That pattern requires all units to be present in the string (which will not always be the case..)
Try something like this instead:
| Code: | | regsub -all { ([wdhms])[^ ]+} $timeago \\1 timeago |
or
| Code: | | set timeago [string map {" weeks" w " week" w " days" d " day" d " hours" h " hour" h " minutes" m " minute" m " seconds" s " second" s} $timeago] |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
Access Voice
Joined: 04 Jun 2006 Posts: 22
|
Posted: Mon Dec 11, 2006 10:26 am Post subject: |
|
|
| rosc2112 wrote: |
| Code: | | set timeago [string map {" weeks" w " week" w " days" d " day" d " hours" h " hour" h " minutes" m " minute" m " seconds" s " second" s} $timeago] |
|
Works great, thx!
And whats about the $mytime variable? anyone an idea to solve this? |
|
| Back to top |
|
 |
user

Joined: 18 Mar 2003 Posts: 1452 Location: Norway
|
Posted: Mon Dec 11, 2006 11:38 am Post subject: |
|
|
| Code: | | clock format $unxtime -format "%d.%m.%Y %T" |
_________________ Have you ever read "The Manual"? |
|
| Back to top |
|
 |
Access Voice
Joined: 04 Jun 2006 Posts: 22
|
Posted: Mon Dec 11, 2006 12:47 pm Post subject: |
|
|
???
do u know what i want?
i want to convert
| Code: | | 2006-10-28 00:08:42 |
or
to
| Code: | | 28.10.2006 00:08:42 |
|
|
| Back to top |
|
 |
Sir_Fz Revered One

Joined: 27 Apr 2003 Posts: 3793 Location: Lebanon
|
Posted: Mon Dec 11, 2006 1:20 pm Post subject: |
|
|
Yeah, and that's what you got. $unxtime in this case would be '1161986922'. _________________ Follow me on GitHub
- Opposing
Public Tcl scripts |
|
| Back to top |
|
 |
rosc2112 Revered One

Joined: 19 Feb 2006 Posts: 1454 Location: Northeast Pennsylvania
|
Posted: Mon Dec 11, 2006 1:50 pm Post subject: |
|
|
| I dunno why I didn't think of using [string map] that would be simpler =) |
|
| Back to top |
|
 |
|