11-03-2022, 05:17 PM
It's the way I was taught originally by QB64 Wiki. Go ahead and try to write it as a function; the way I write it works for me.
Another way. First this C header file called "strf.h":
Then this BASIC file which must be in the same directory as the header file and QB64PE executable:
Use if it you want, but this was for showing off. My first attempt was to declare "strftime()" directly in "DECLARE" block but kept getting a C++ compilation error about the type of the last parameter. It looks like the C++ compiler expected a "double pointer" which is constant or something like that.
This duo could be customized even further, such as adding another string argument for the "format", to be able to get "2022-Nov-03" as well as the time, or something else with the date and time.
Another way. First this C header file called "strf.h":
Code: (Select All)
#include <string.h>
#include <time.h>
void getstrftime(short h, short m, short s, char * sout)
{
struct tm tthis;
size_t fret, soutlen;
tthis.tm_sec = s;
tthis.tm_min = m;
tthis.tm_hour = h;
soutlen = strlen(sout);
fret = strftime(sout, soutlen, "%H:%M:%S", &tthis);
}
Then this BASIC file which must be in the same directory as the header file and QB64PE executable:
Code: (Select All)
declare library "strf"
sub getstrftime(byval h as integer, byval m as integer, byval s as integer, soutput as string)
end declare
dim sout$
dim as integer hh, mm, ss
hh = 4
mm = 1
ss = 5
sout$ = space$(20)
getstrftime hh, mm, ss, sout$
print sout$
end
Use if it you want, but this was for showing off. My first attempt was to declare "strftime()" directly in "DECLARE" block but kept getting a C++ compilation error about the type of the last parameter. It looks like the C++ compiler expected a "double pointer" which is constant or something like that.
This duo could be customized even further, such as adding another string argument for the "format", to be able to get "2022-Nov-03" as well as the time, or something else with the date and time.