Microsoft KB Archive/43331: Difference between revisions

From BetaArchive Wiki
m (Text replacement - "<" to "<")
m (Text replacement - "&" to "&")
 
(One intermediate revision by the same user not shown)
Line 77: Line 77:
The following is the sample program:
The following is the sample program:
<pre class="codesample">/* Note - this code takes a couple of minutes to run */  
<pre class="codesample">/* Note - this code takes a couple of minutes to run */  
#include <stdio.h&gt;
#include <stdio.h>
#include <dos.h&gt;
#include <dos.h>
struct dosdate_t Date;
struct dosdate_t Date;
struct dostime_t Time;
struct dostime_t Time;
unsigned long loop;
unsigned long loop;
void main(void)  {
void main(void)  {
   _dos_getdate(&amp;Date);      /* Show time when starting */  
   _dos_getdate(&Date);      /* Show time when starting */  
   _dos_gettime(&amp;Time);
   _dos_gettime(&Time);
   printf (&quot;Today's date is %d-%d-%d\n&quot;, Date.month, Date.day,
   printf (&quot;Today's date is %d-%d-%d\n&quot;, Date.month, Date.day,
           Date.year);
           Date.year);
Line 91: Line 91:
   Date.year = 1988;
   Date.year = 1988;
   for (loop = 1; loop <= 200000; loop++) {
   for (loop = 1; loop <= 200000; loop++) {
       _dos_setdate(&amp;Date);
       _dos_setdate(&Date);
   }
   }


   _dos_getdate(&amp;Date);      /* Show time after loop */  
   _dos_getdate(&Date);      /* Show time after loop */  
   _dos_gettime(&amp;Time);
   _dos_gettime(&Time);
   printf (&quot;Date is now %d-%d-%d\n&quot;, Date.month, Date.day, Date.year);
   printf (&quot;Date is now %d-%d-%d\n&quot;, Date.month, Date.day, Date.year);
   printf (&quot;End time = %d:%d\n&quot;, Time.hour, Time.minute);
   printf (&quot;End time = %d:%d\n&quot;, Time.hour, Time.minute);

Latest revision as of 14:14, 21 July 2020

Knowledge Base


Changing System Time or Date Will Temporarily Pause Clock

Article ID: 43331

Article Last Modified on 12/12/2003



APPLIES TO

  • The C Run-Time (CRT), when used with:
    • Microsoft C Professional Development System 5.1
    • Microsoft C Professional Development System 6.0
    • Microsoft C Professional Development System 6.0a
    • Microsoft C Professional Development System 6.0a
    • Microsoft C/C++ Professional Development System 7.0
    • Microsoft Visual C++ 1.0 Professional Edition
    • Microsoft Visual C++ 1.5 Professional Edition



This article was previously published under Q43331

SUMMARY

The system clock temporarily pauses when the time or the date is set. This feature prevents cases in which the date or time may need to be updated during the actual time change. For example, an attempt to set the system date exactly at midnight using _dos_setdate() will not produce the desired effect if the system changes the date at the same time it is being set. Therefore, the system clock pauses.

The effects of such a pause can be seen in the sample program that follows. If you run this program, you will find upon exit that the system time is the same as when the program was started.

MORE INFORMATION

The following is the sample program:

/* Note - this code takes a couple of minutes to run */ 
#include <stdio.h>
#include <dos.h>
struct dosdate_t Date;
struct dostime_t Time;
unsigned long loop;
void main(void)  {
   _dos_getdate(&Date);       /* Show time when starting */ 
   _dos_gettime(&Time);
   printf ("Today's date is %d-%d-%d\n", Date.month, Date.day,
           Date.year);
   printf ("Start time = %d:%d\n", Time.hour, Time.minute);

   Date.year = 1988;
   for (loop = 1; loop <= 200000; loop++) {
      _dos_setdate(&Date);
   }

   _dos_getdate(&Date);       /* Show time after loop */ 
   _dos_gettime(&Time);
   printf ("Date is now %d-%d-%d\n", Date.month, Date.day, Date.year);
   printf ("End time = %d:%d\n", Time.hour, Time.minute);
}
                


Additional query words: kbinf 6.00 6.00a 6.00ax 7.00 1.00

Keywords: kb16bitonly KB43331