Getting and Setting System Date 
Author Message
 Getting and Setting System Date

Newbie here.  I am trying to write a program which, among other
things, can get the system date, store it in a variable, and also
change the system date.  I am working under Windows (98 and 2000),
using MS Visual Studio.  I looked under Visual Studio help for
something that would get and set the system date, and also store the
date in a variable.  I found instructions for getting the current date
and time, and storing that in a variable (I've reproduced the
instructions below, for the benefit of interested parties).  But I
couldn't find anything about how to reset the system date (and I want
to do it directly in code, not by calling up a dialog box).  In other
words, there was no CTime::SetCurrentDateTime function, or anything
along those lines.  Can anyone help me out?

Thanks,
CJ

To get the current time
1.      Allocate a CTime object, as follows:

2.      CTime theTime;
Note   Uninitialized CTime objects are not initialized to a valid
time.

3.      Call the CTime::GetCurrentTime function to get the current time
from the operating system. This function returns a CTime object that
can be used to set the value of CTime, as follows:

4.      theTime = CTime::GetCurrentTime();

Since GetCurrentTime is a static member function from the CTime class,
you must qualify its name with the name of the class and the scope
resolution operator (::), CTime::GetCurrentTime().

Of course, the two steps outlined previously could be combined into a
single program statement as follows:

CTime theTime = CTime::GetCurrentTime();



Mon, 05 Sep 2005 05:42:38 GMT  
 Getting and Setting System Date

wrote in comp.lang.c++:

Quote:
> Newbie here.  I am trying to write a program which, among other
> things, can get the system date, store it in a variable, and also
> change the system date.

        [snip]

You cross-posted this to comp.lang.c++ and alt.comp.lang.learn.c-c++,
both of which are discuss the standard C++ language and not the
Windows API or any other platform specific library.

As far as standard C++ is concerned, there are functions prototyped in
<time.h> or <ctime> that can get the system data and time.  Standard
C++ does not provide any way to modify the system date.

        [snip]

  But I

Quote:
> couldn't find anything about how to reset the system date (and I want
> to do it directly in code, not by calling up a dialog box).  In other
> words, there was no CTime::SetCurrentDateTime function, or anything
> along those lines.  Can anyone help me out?

> Thanks,
> CJ

There is no CTime class in C++, this is a Microsoft extension for the
Windows API, and as such it is off-topic in newsgroups that discuss
the standard language.

In the future please leave comp.lang.c++ and alt.comp.lang.learn.c-c++
off of posts about Windows and MFC specific functions.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq



Mon, 05 Sep 2005 06:39:30 GMT  
 Getting and Setting System Date



<snipped>

Quote:
>instructions below, for the benefit of interested parties).  But I
>couldn't find anything about how to reset the system date (and I want
>to do it directly in code, not by calling up a dialog box).  In other
>words, there was no CTime::SetCurrentDateTime function, or anything
>along those lines.  Can anyone help me out?

>Thanks,
>CJ

<snipped>

Hi,

Perhaps you could use this Win32 API function
SetSystemTime

For more information, the MSDN location is:
Platform SDK -> Windows Base Services -> General Library ->Time

If I'm not mistaken, I believe it is possible to call a Win32 API
function from within an MFC application.

Hope this helps,

Best Regards,
Yeoh
--
Free download C++ eBook
http://www.yeohhs.com



Mon, 05 Sep 2005 06:45:39 GMT  
 Getting and Setting System Date


Quote:
>Newbie here.  I am trying to write a program which, among other
>things, can get the system date, store it in a variable, and also
>change the system date.

As far as I know, setting the system date is not possible with
standard C++, which rules out an answer from comp.lang.c++ or
alt.comp.lang.learn.c-c++. All the stuff about "CTime" is
non-standard, and off-topic in both these groups. The standard way to
retrieve the current date/time is to use functions from <ctime> (the
name of which refers to the time library C++ inherited from C and has
nothing to do with the CTime class). Check your C or C++ reference for
details (remember that the names must be prefixed with std:: in a C++
program unless you bring the names into scope with "using"
declarations).

To other people replying to this question, please keep replies that
deal with non-standard extensions and libraries off comp.lang.c++ and
alt.comp.lang.learn.c-c++. Thanks.

-Kevin



Mon, 05 Sep 2005 06:58:15 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Getting or Setting regional settings for date/time format from an application

2. Need help with getting the system date on the file server

3. Getting system date/time at midnight?

4. Newbie Question: how to set system date

5. Get and Set system date...

6. Settings|System (tab)|Regional Settings | Region setting other than English (US) causes problem in VarBstrFromDate

7. Set Date in Date Time Picker

8. Setting / getting list separator (Regional Setting Properties)???

9. Is there any way to get the System date and n days back from the system date in ATL

10. Getting Number of Months and Days between two dates

11. getting time/date

12. Getting todays date?

 

 
Powered by phpBB® Forum Software