Trying to convert seconds to minutes Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
User avatar
JoeWinograd
Posts: 1608
Joined: 10 Feb 2014, 20:00

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:07

BoBo wrote:I've reduced a few lines of it
Hi BoBo,
I intentionally do not reduce lines of code. I prefer clarity over brevity in my code. I find that when others try to utilize my code (enhance/maintain it), clarity rather than brevity is extremely helpful. In fact, that's even true when I go back to look at my own code a year later. :)
BoBo wrote:What about making the hours also two-digit values?
You could do that (with the same line of code that I used for minutes and seconds), but the reason I didn't is that, theoretically, it could be any number of hours, such as 100 or 1000. Regards, Joe
User avatar
SKAN
Posts: 807
Joined: 29 Sep 2013, 16:58

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:13

RedFeather wrote:

Code: Select all

	GuiControl,, displayV2, %  format("{:0.2f}", AV2duration)  				;; Ive tried many of the obvious things atleast to me, format time, format seconds function ive found. The closest thing i can get is the lame AV2duration  /= 60  
My take:

Code: Select all

GuiControl,, displayV2, %  FmtSecs(AV2duration, "{6:3}:{4:02}")
You can get FmtSecs() here: https://www.autohotkey.com/boards/viewtopic.php?t=77420
User avatar
JoeWinograd
Posts: 1608
Joined: 10 Feb 2014, 20:00

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:17

RedFeather wrote:Thank you for taking the time to do this!!Works great!
Hi RF,
You're very welcome. I'm glad to hear that it's working great for you. Cheers, Joe
BoBo
Posts: 3755
Joined: 13 May 2014, 17:15

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:26

@Joe ; bc of 'weekend/vacation'-dementia I prefer heavy commenting over extra lines of code :lol:
@SKAN Thx for your function! Much appreciated :thumbup:
User avatar
JoeWinograd
Posts: 1608
Joined: 10 Feb 2014, 20:00

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:33

BoBo wrote:I prefer heavy commenting over extra lines of code
I'm pretty much with you on that, although I would say heavy commenting in addition to extra lines of code...and long, self-descriptive variable names, too.
User avatar
SKAN
Posts: 807
Joined: 29 Sep 2013, 16:58

Re: Trying to convert seconds to minutes

30 Aug 2020, 18:47

BoBo wrote:
30 Aug 2020, 18:26
@SKAN Thx for your function! Much appreciated :thumbup:
Thanks to you.. Your gms() - GetMilliseconds was the inspiration.
I wrote this function 1 day later. :D :thumbup:
RedFeather
Posts: 13
Joined: 23 Jan 2020, 23:38

Re: Trying to convert seconds to minutes

30 Aug 2020, 19:15

WOW Really guys thank you for the help so many ways for me to learn its exciting! I appreciate each and every response!
Rohwedder
Posts: 3492
Joined: 04 Jun 2014, 08:33
Location: Germany

Re: Trying to convert seconds to minutes

31 Aug 2020, 07:12

Hallo,
what have you all against RegEx?

Code: Select all

MsgBox % hms:=FormatSeconds(3778)	; should show 01:02:58
MsgBox % hms:=FormatSeconds(178)	; should show    02:58
MsgBox % hms:=FormatSeconds(58)		; should show	 00:58
MsgBox % hms:=FormatSeconds(-58)	; should show	 00:00
ExitApp
FormatSeconds(noSec)  ; Convert the specified number of seconds to hh:mm:ss format.
{
    Time = 19990101  					; *Midnight* of an arbitrary date.
    Time += Max(noSec, 0), s 			; negative noSec becomes zero
    FormatTime, Time,% Time, HH:mm:ss 	; force hours to two digits
    Return, RegExReplace(Time, "\A00:") ; removes empty hours
}
BoBo
Posts: 3755
Joined: 13 May 2014, 17:15

Re: Trying to convert seconds to minutes

31 Aug 2020, 10:19

what have you all against RegEx?
Probably it's that 'Ex'-thing (like in Ex-wife)?? You know it exists, you know it can make you feel helpless, so you try to bypass any situation where it can ruin your day :lol: :mrgreen: :lolno: :shh: Thx for sharing your code :thumbup:
User avatar
JoeWinograd
Posts: 1608
Joined: 10 Feb 2014, 20:00

Re: Trying to convert seconds to minutes

31 Aug 2020, 13:03

Rohwedder wrote:what have you all against RegEx?
I'm with Jamie Zawinski (or whoever really deserves the credit for it) on this one:
Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
That said, there are occasional times when a RegEx is indispensable. Most other times, string functions will do the trick with far more clarity and code maintainability...just one person's opinion, of course. Regards, Joe
User avatar
jNizM
Posts: 2662
Joined: 30 Sep 2013, 01:33
GitHub: jNizM
Contact:

Re: Trying to convert seconds to minutes

01 Sep 2020, 02:28

https://www.autohotkey.com/boards/viewtopic.php?f=6&t=10082 (GetXxxFormat Functions) will finish this today
[AHK] 1.1.32.00 x64 Unicode | [WIN] 10 Pro (Version 2004) x64 | [GitHub] Profile
Donations are appreciated if I could help you
garry
Posts: 2430
Joined: 22 Dec 2013, 12:50

Re: Trying to convert seconds to minutes

01 Sep 2020, 04:26

@ALL
thank you for the many examples / functions , have much to learn ...

Return to “Ask For Help”

Who is online

Users browsing this forum: austin4149, Google [Bot], mikeyww and 31 guests