Jump to content
Tuts 4 You

How to convert seconds to full time?


Recommended Posts

Hey guys,


I have a short question again about how to convert seconds in normal time HH:MM:SS you know what I mean right.So how can I do this via code?

HH:MM:SS = 05:23:40
5 = 18000
23 = 1380
40 = 40
19420 seconds

Just imagine that I only have the seconds of 19420 to work with.How can I calc now the result in HH:MM:SS on the simplest way?Is there any API which I could use etc where I just push the seconds in hex and to get also the values for HH:MM:SS back etc?So the only thing what I can do is to get it all just separately HH and MM and SS (5:323:19420).


Maybe you can help again how to handle this.


Thank you

Link to comment
Share on other sites

sec = 19420

if sec >= 3600 then

ho= sec \ 3600


min= sec mod 3600

sec = min mod 60


if min >= 60 then

min = min \ 60

Link to comment
Share on other sites

c code

// Desc: Converts a number of seconds to an ASCII string
//           number of time in hour:minute:second format
// Args: Seconds = long seconds wanting to convert
//          Result = buffer where result will be stored

void ConvertSecToTime(long seconds, char Result[20])
    long hr, min, sec, t;    hr = seconds / 3600;    t = seconds % 3600;    min = t/60;    sec = t % 60;    sprintf(Result, "%ld:%ld:%ld", hr, min, sec);
}int main(int argc, char *argv[])
{    long Seconds = 19421;    char TimeFromSeconds[20];    ConvertSecToTime(Seconds, &TimeFromSeconds[0]);    printf("%s\n", &TimeFromSeconds[0]);    _getch ();

    return EXIT_SUCCESS;




i think u want this for masm? hopefully u can use the picture to see the asm function you want @401390, or copy/paste directly from the compiled binary



binary - lcfatconv.rar - 104 KB


mov dword ptr ss:[esp+4], eax ; eax = 22ff40 address where result will be storedmov dword ptr ss:[esp], Seconds ; Seconds = 4bddh = 19421dcall 401390 ; call ConvertSecToTime()22ff20 = "5:23:41" 
Link to comment
Share on other sites

Hi again,


coolio and thank you guys for your links / infos & nice tools. :) So now its working as it should be or as I wanted also if I don't really understand the calc process for 100 % (call ConvertSecToTime routine by simple) but it works. :) Thank you again for this.


Ok I have one another tiny question.So now I want to get the language (Name as string) of a system using the API GetSystemDefaultLangID.So after this I have the ID word = 0407 (Germany) in my case.So the problem now I have is to get the language string by ID.So is there any API which I can call with this ID to get the Germany string back?So I only see that there should be any MAKELANGID struct or so to identify the language string.Now I have no MAKELANGID file or header file where its stored and the other question is is there not a MAKELANGID file already on any system stored?You know what I mean right.Just wanna call any API xy with the ID I have to get the language string back. :) Maybe you guys can help again with this a little (tiny tool again + routine address to check this).


Thank you

Link to comment
Share on other sites


// this is the MAKELANGID macro, the "official way" but even MS says that system of IDing language
// from country is garbage because it doesnt save time coding so i did a function
// to return hardcoded strings from constants. i only coded the more common languages
// and not all thousands of combos 0x00 - 0x03ff #define MAKELANGID(p, s) ((((WORD)(s)) << 10) | (WORD) (p)) // Desc: Returns pointer to ASCII string in format
// Args: WORD LangID is return value of GetSystemDefaultLangID()
char* GiveMeTheLanguage(WORD LangId)
{ if (WORD == NULL)
goto END; else if (WORD == 0x0409)
... many lang entries go here... END:
char* RetVal = "UNKNOWN";
return RetVal;
int main()
char* Language = GiveMeTheLanguage(GetSystemDefaultLangID());
printf("%s", Language);
return 0;




start of GiveMeTheLanguage() function == 401390 , ends at 4020d6


lcfatsyslang.rar - 105 KB


call GetSystemDefaultLangID() ; get WORD LangID
mov eax, ax ; put result in eax
mov dword ptr esp, eax ; put result on top of stack
call GiveMeTheLanguage() ; call funciton 401390 in binary
string DWORD PTR SS pointer returned in EAX

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Create New...