Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting System Time

Status
Not open for further replies.

moonoo

Programmer
May 17, 2000
62
US
Hi
How to get the System time without using the MFC classess
CTime and CString..
I want the date and time in the YYYY/MM/DD HH:MM:SS format
and i am using the follwing code

time_t ltime ;
char tmpbuf[128] ;
struct tm *today;
today = localtime( &ltime );
strftime(tmpbuf,25,"%Y/%m/%d %H:%M:%S",today);

This funcyion is giving the Date 1970/01/01 09:00:00 in stead of the current time and date..
Is there some others structures and functions available by which i can get the current date and time by the above method(without using the MFC Classes)

Please give an early reply..
Dev
 
Consider the two Api Function:
- GetSystemTime syntax
VOID GetSystemTime(
LPSYSTEMTIME lpSystemTime // system time
- GetLocalTime syntax
VOID GetLocalTime(
LPSYSTEMTIME lpSystemTime // system time
);

The second function will return the system time taking into acoont the Time Zone you are in. I think you will need this one more often.

Hope this helps, s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Thanks for the reply ..
How do i change the LPSYSTEMTIME to the desried format
I want the date in YYYY/DD/MM HH:MM:SS in a charecter
Array .
Please reply at the earlist
Dev
 
the SYSTEMTIME(not LPSYSTEMTIME, use the & operator) has the following structure:
typedef struct _SYSTEMTIME {
WORD wYear;
WORD wMonth;
WORD wDayOfWeek;
WORD wDay;
WORD wHour;
WORD wMinute;
WORD wSecond;
WORD wMilliseconds;
}
There is no default function for the exact format you want but you can use the sprintf and wsprintf functions. (do not forghet to #include <stdio.h>) - (Don't ask me how)

Hope this helps,

s-)

Blessed is he who in the name of justice and good will, shepards the week through the valley of darknees...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top