View Full Version : GetSystemTime, cant get it to work... Any other options?
PPCdev
02-20-2003, 09:14 AM
eVC:MFC
Trying to get GetSystemTime to work, Ive tried 6 different things, read sample code from 12 different sites, but no real details on how I call it, or use it.
At any rate, I read it returns the UTC anyway, and I really want the date and time information as you would get when you tap on the Clock on the Today Screen.
Any suggestions, with snippit or a bit of code to get me started?
Thanks,
Andrew
VanHlebar
02-20-2003, 09:47 PM
Andrew,
I am at work right now and do all my developing at home, so I can't give you any code at the present time. Have you looked at using either CTime or COleDateTime classes? I belive that CTime can be constructed by defualt with the current system time. I know that when I was using dates and times in a Calander application awhile back, I used CTime and COleDateTime extensively. If I get time when I get home this evening I will try to post some code.
-Eric
PPCdev
02-20-2003, 10:15 PM
Thanks for the info, Ill look into it. It would still be helpful for a reply though, just starting out Im having some difficulty understanding classes all together and not entirly sure how to impliment the code. :-(
Sorry, but I am learning! At least Im not asking how I make a form now! HEHE! Gosh, we were all newbies at one time I reckon...
Thanks again,
Andrew
PPCdev
02-20-2003, 11:06 PM
This code:
void CShowTimeDlg::OnOK()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
MessageBox( asctime(timeinfo));
}
Results in this information:
http://pocketblast.com/images/cproj-showtime.jpg
Its more information that I wanted. Can I use any type of formatting to extract the time in specific, or just the date?
Id like to be able to assign to a var each of the following returns: Day Month Year Hour Minute Second DayOfWeek.
Any further advice or suggestions would be helpful.
Thanks!
Andrew
VanHlebar
02-21-2003, 01:26 PM
This code:
void CShowTimeDlg::OnOK()
{
time_t rawtime;
struct tm * timeinfo;
time ( &rawtime );
timeinfo = localtime ( &rawtime );
MessageBox( asctime(timeinfo));
}
Its more information that I wanted. Can I use any type of formatting to extract the time in specific, or just the date?
Id like to be able to assign to a var each of the following returns: Day Month Year Hour Minute Second DayOfWeek.
Any further advice or suggestions would be helpful.
Thanks!
Andrew
Andrew,
I have not tested the following, but I think it should work.
// example for CTime::CTime
CTime m_Time = CTime::GetCurrentTime();
//Now you can get the different variables.
int nMonth = m_Time.GetMonth();
int nYear = m_Time.GetYear();
int nDay = m_Time.GetDay();
int nDayofWeek = m_Time.GetDayofWeek();
int nHour = m_Time.GetHour();
int nSecond = m_Time.GetSecond();
Hope this helps. You can do the same type of stuff with COleDateTime. Both are documented in the help files if you need more reading. :)
-Eric
PPCdev
02-21-2003, 01:50 PM
"Both are documented in the help files if you need more reading"
Part of my problem, being at this beginner stage with VC is, I dont entirly understand everything Im reading in the Help file, or on various sites; usegroups. A bit of it makes sense, a lot of it doesnt. Thats up 10% from none of it makes sense. HAHA!
I spent over 15 years programming in BASIC and VB, thats about 14.5 years too long, and should have started learning C about 14.75 years ago. I think that var is long, would have to check...
void EradicateVisualBasic()
{
// TODO: Add code below to remove VisualBasic from the world
}
I do thank you much for your reply, Ill diddle with the code and see what comes out!
Andrew
VanHlebar
02-21-2003, 02:08 PM
"Both are documented in the help files if you need more reading"
Part of my problem, being at this beginner stage with VC is, I dont entirly understand everything Im reading in the Help file, or on various sites; usegroups. A bit of it makes sense, a lot of it doesnt. Thats up 10% from none of it makes sense. HAHA!
Andrew
Andrew,
I was not intending that to sound the way it reads. I apologize, I too am fairly new at eVC++. I would highly recommend a book called MFC From the Ground UP, Second Edition. It is a Windows programming book, specifically geared towards MFC. It shows you how to construct programs first manually, then how to use the wizards. Most of the code will port over to ppc as long as you remember that the ppc enviroment is Unicode and not ANSI. I don't remember the author off the top of my head, but it is a great book and it was I used when I decided to jump into the eVC++ world.
Don't stop asking questions. :) I frequent this forum as of recent, and also Code Project and you could also goto Pocket Projects. Pocket Projects is specifically for the ppc development but it is kind of slow, not much traffic over there.
Keep plugging and good luck! :)
-Eric
PPCdev
02-22-2003, 01:38 AM
"I was not intending that to sound the way it reads. I apologize"
Hoss, no apologies needed! I didnt take offense, I only quoted that so you would understand my reply, Im only saying I dont understand what I read most of the time. Thats all I was saying, not sure how you may have not understood that, but at any rate, there is no apology needed!
Im new to the forum, and I want others that are trying to help understand my level at this point, that is, Im new, and I dont understand much of what Im reading yet. Im learning more every day, but its slow. :-(
Thats all-- Dont worry-- Be happy! :-)
Cheers,
Andrew
PPCdev
02-22-2003, 03:39 AM
Van! Most outstanding! You help was right on target! With a minor typo of needing capitol 'O' in DayOfWeek. :-)
From what you gave me, I was able to expand on it, learn from it and put it into an executable with no link errors! HAHA! Hey, Ive come a looong way baby! HAHA!
The following code is the result of my toils:
// example for CTime::CTime
CTime m_Time = CTime::GetCurrentTime();
// Now you can get the different variables.
int nMonth = m_Time.GetMonth();
int nYear = m_Time.GetYear();
int nDay = m_Time.GetDay();
int nDayOfWeek = m_Time.GetDayOfWeek();
int nMinute = m_Time.GetMinute();
int nHour = m_Time.GetHour();
int nSecond = m_Time.GetSecond();
CString Rval;
CString TempString;
// Code below is for debug/test
// Rval.Format(("%d"), nYear);
// Rval = "Return value: " + Rval;
// MessageBox (Rval);
// Build the string and put in EditBox
// m_EditBox is var
Rval = "The current time information for this system is: \r\n";
TempString.Format(("%d"), nHour);
Rval = Rval + "Current Hour: " + TempString + " \r\n";
TempString.Format(("%d"), nMinute);
Rval = Rval + "Current Minute: " + TempString + " \r\n";
TempString.Format(("%d"), nSecond);
Rval = Rval + "Current Second: " + TempString + " \r\n";
TempString.Format(("%d"), nMonth);
Rval = Rval + "Current Month: " + TempString + " \r\n";
TempString.Format(("%d"), nDay);
Rval = Rval + "Current Day: " + TempString + " \r\n";
TempString.Format(("%d"), nYear);
Rval = Rval + "Current Year: " + TempString + " \r\n";
TempString.Format(("%d"), nDayOfWeek);
Rval = Rval + "Current Day of week: " + TempString + " \r\n";
// Assign the EditBox var the text we built
m_EditBox = Rval;
// Update the box
UpdateData(false);
The resulting executable:
http://pocketblast.com/images/cproj-showtime2.jpg
Again, mega many thanks friend! Its help like yours that gets me on track and productive, and all the while Im learning the syntax and structure. I posted the full code and resulting screen cap so I can pass on that help to someone else that may be following my foot steps.
Im keeping all progress with any function or action in a directory with programmer's notes. When I get up to snuff and most of the major stuff covered I hope to format them with proper text and graphics and compile them to PDF for others to learn by. (Wish me luck on that project! HAHA)
Andrew
vBulletin® v3.8.9, Copyright ©2000-2019, vBulletin Solutions, Inc.