| View previous topic :: View next topic |
| Author |
Message |
.AHK
Joined: 26 Apr 2006 Posts: 657 Location: New Mexico, USA
|
Posted: Thu Aug 24, 2006 8:05 am Post subject: Easy Milliseconds (Second, Minute, Hour) |
|
|
| Code: |
Sec =
Sec := (Sec*1000)
Min =
Min := (Min*60000)
Hour =
Hour := (Hour*3600000)
SMH := (Sec+Min+Hour)
|
Sorry if this has been posted before. I know some people must have thought it up already. If you want to sleep for 1 hour 32 minutes 5 seconds you would set it up like this:
| Code: |
Sec = 5
Sec := (Sec*1000)
Min = 32
Min := (Min*60000)
Hour = 1
Hour := (Hour*3600000)
SMH := (Sec+Min+Hour)
Sleep, %SMH%
|
Or of course the Sec, Min, Hour variable can be modified throughout the script.
Last edited by .AHK on Sat Sep 23, 2006 1:09 am; edited 1 time in total |
|
| Back to top |
|
 |
SKAN
Joined: 26 Dec 2005 Posts: 8688
|
Posted: Thu Aug 24, 2006 1:17 pm Post subject: |
|
|
Dear .AHK,
It can be simplified with a function like:
| Code: | Str2Sec(Time) {
StringSplit,F,Time,`:
Return ((F1*3600)+(F2*60)+F3)
} |
Examples:
| Code: | | Sleep, Str2Sec("01:32:05")*1000 |
| Code: | | MsgBox, 64, MessageBox, Press Ok, % Str2Sec("01:32:05") |
Regards,  _________________ URLGet - Internet Explorer based Downloader |
|
| Back to top |
|
 |
.AHK
Joined: 26 Apr 2006 Posts: 657 Location: New Mexico, USA
|
Posted: Sat Sep 23, 2006 1:19 am Post subject: |
|
|
Now that I know the basics of functions I thought I would give this a try.
| Code: |
easyMS(h, m, s) {
S := (S*1000)
M := (M*60000)
H := (H*3600000)
SMH := (S+M+H)
Return SMH
} |
To use it in a sleep I think it would be like this.
| Code: |
Sleep % easyMS(1, 35, 30)
|
Correct? Sleep for 1 hour, 35 minutes, 30 seconds. |
|
| Back to top |
|
 |
PhiLho
Joined: 27 Dec 2005 Posts: 6836 Location: France (near Paris)
|
Posted: Mon Sep 25, 2006 10:19 am Post subject: |
|
|
| AHK's Manual, Sleep page wrote: | | Delay The amount of time to pause (in milliseconds) between 0 and 2147483647 (24 days), which can be an expression. | No need to write Sleep % easyMS(...) _________________
vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2") |
|
| Back to top |
|
 |
.AHK
Joined: 26 Apr 2006 Posts: 657 Location: New Mexico, USA
|
Posted: Mon Sep 25, 2006 10:44 am Post subject: |
|
|
| Quote: | | No need to write Sleep % easyMS(...) |
So a sleep automatically considers its parameter to be an expression without the %?
| Code: |
Sleep easyMS(1,2,5)
|
|
|
| Back to top |
|
 |
polyethene
Joined: 11 Aug 2004 Posts: 5248 Location: UK
|
Posted: Mon Sep 25, 2006 10:58 am Post subject: |
|
|
| .AHK wrote: | | So a sleep automatically considers its parameter to be an expression without the %? |
Yes because it accepts expressions. This is a simplified version of your function: | Code: | toMS(h, m = 0, s = 0, ms = 0) {
return ms + (h * 3600 + m * 60 + s) * 1000
} |
|
|
| Back to top |
|
 |
berban
Joined: 30 Dec 2009 Posts: 159 Location: Worcester, Massachusetts
|
Posted: Sun Jun 20, 2010 10:32 pm Post subject: |
|
|
You also don't need to escape the colon.
| Code: | | StringSplit, Time, Time, : |
_________________ ★★★ Email me at berban at aim full stop com ★★★ |
|
| Back to top |
|
 |
RaptorX
Joined: 19 Feb 2010 Posts: 580
|
Posted: Mon Jun 21, 2010 11:43 am Post subject: |
|
|
Interesting how you can do the same thing in other ways...
I have always used the following to make time calculations:
| Code: |
sec := 1000
min := 60 * sec
hour := 60 * min
Sleep 5 * sec
|
All my scripts have those variables in case I want to use them for tooltips or Sleep timers, because it makes it very easy to read.
If I want to make specific calculations I would do the following:
| Code: |
sleep 1 * hour + 20 * min + 30 * sec ; 1h:20m:30sec
|
I dont need to use a function for that  |
|
| Back to top |
|
 |
|