system date and time using C++
can anyone explain me how do i show current date and time (system date) on screen and assign it to a parameter (an object or a string or double) using C++?
Thanks !
[168 byte] By [
PsSheba] at [2007-11-18 21:41:47]

# 1 Re: system date and time using C++
One solution is an edit box.
Kuphryn
# 2 Re: system date and time using C++
But still: how do i get from the system its date and time ?
I dont think it has got anything to do with editing.
# 3 Re: system date and time using C++
What kind of system are you using? You say "using C++", but a feature like this is "system"-dependent.
Do you want to get it from Windows, from DOS, directly from the BIOS, etc.?
Bond at 2007-11-9 0:36:18 >

# 4 Re: system date and time using C++
Though it could be any other textual os.
# 5 Re: system date and time using C++
Originally posted by PsSheba
can anyone explain me how do i show current date and time (system date) on screen and assign it to a parameter (an object or a string or double) using C++?
Thanks !
you can use the header file #include<time.h>
in it you can get:
std::gmtime()and std::localtime
for example
#include<iostream.h>
#include<time.h>
int main()
{
time_t now=time(0);
cout<<asctime(gmtime(&now));
return 0;
}
it will display the greenwich time and asctime(i)is used to show the result
surely the c++ has something with the version
i.e the compilers differs from versions
if you use the compilere GNU(Quiny),then you should pay attention to your code ,sometimes it cannot do what you want it to !
for example #include<ctime.h>is not used in my compiler
you can see more about the time header file
# 6 Re: system date and time using C++
Originally posted by kuphryn
One solution is an edit box.
Kuphryn
but kuphryn and Bond how to do that with a edit_boxing can you tell me in details?
please
# 7 Re: system date and time using C++
Here's a Win32 example:
// Get the local time...
SYSTEMTIME stCurrent = {0};
GetLocalTime(&stCurrent);
// Format the date and time...
TCHAR szDate[64];
TCHAR szTime[64];
GetDateFormat(LOCALE_SYSTEM_DEFAULT, NULL, &stCurrent, TEXT("dddd',' MMMM d, yyyy"),
szDate, sizeof(szDate) / sizeof(TCHAR));
GetTimeFormat(LOCALE_SYSTEM_DEFAULT, NULL, &stCurrent, TEXT("h':'mm tt"),
szTime, sizeof(szTime) / sizeof(TCHAR));
// We now have szDate and szTime. Assign to edit box...
SetWindowText(hwndEditDate, szDate);
SetWindowText(hwndEditTime, szTime);
Bond at 2007-11-9 0:40:28 >

# 8 Re: system date and time using C++
Thats what i was looking for.