Simple C Question
Hello everybody!
My question is very simple (it''s quite embarrassing for me), and sure is very easy to answer.
How do I ask for the current date/time, and best convert it into a string in C? It would be very good if you could tell me the include-file as well where to find those functions.
Thanks in advance!
Indeterminatus
--si tacuisses, philosophus mansisses--
Indeterminatus--si tacuisses, philosophus mansisses--
Hey,boy,your question is not-so clear - what platform where your program will run and what computer language you will write the program?...
I am now suppose the answers to the above 2 questions are MS Windows and C/C++,so you can do that as the following:
#include "Windows.h"
...
SYSTEMTIME SysTime;
BOOL bRet=GetLocalTime(&SysTime);
if (bRet)
{
//call successful
TCHAR szTimeText[100];
//convert the date/time to a ANSI text string...
spritf(szTimeText,"%d/%02d/%02d %02d:%02d:%02d",SysTime.wMouth,SysTime.wDay,SysTime.wYear,SysTime.wHour,SysTime.wYear.wMinute,SysTime.wYear.wSecond);
//Show the date/time...
printf("The current date & time is %s.",szTimeText);
}
else
{
//failed to call this API
}
...
Hope this helped!
I am now suppose the answers to the above 2 questions are MS Windows and C/C++,so you can do that as the following:
#include "Windows.h"
...
SYSTEMTIME SysTime;
BOOL bRet=GetLocalTime(&SysTime);
if (bRet)
{
//call successful
TCHAR szTimeText[100];
//convert the date/time to a ANSI text string...
spritf(szTimeText,"%d/%02d/%02d %02d:%02d:%02d",SysTime.wMouth,SysTime.wDay,SysTime.wYear,SysTime.wHour,SysTime.wYear.wMinute,SysTime.wYear.wSecond);
//Show the date/time...
printf("The current date & time is %s.",szTimeText);
}
else
{
//failed to call this API
}
...
Hope this helped!
============================= Hey,I just wanna know WHY! =============================
August 26, 2001 07:15 AM
#include
time_t seconds;
char time[];
seconds = time (NULL); //seconds since 1st january 1970
time = ctime(&seconds); //converting to a string
for more information: www.cplusplus.com/ref/
time_t seconds;
char time[];
seconds = time (NULL); //seconds since 1st january 1970
time = ctime(&seconds); //converting to a string
for more information: www.cplusplus.com/ref/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement