Annotation of os2sdk/demos/examples/datetime/datetime.c, revision 1.1.1.2

1.1       root        1: /*
1.1.1.2 ! root        2:  * Example of DosGetDateTime & DosSetDateTime usage
1.1       root        3:  *
                      4:  * These calls are used to set and get the current system time.
                      5:  * Also shows the structure of the information returned.
                      6:  *
1.1.1.2 ! root        7:  *     - on an IBM AT, DosSetDateTime changes the hardware real time clock
1.1       root        8:  *     - the system sets the 'timezone' value to -1 by default
                      9:  *
1.1.1.2 ! root       10:  * Compile as: cl -AL -G0 -Lp datetime.c
1.1       root       11:  *
1.1.1.2 ! root       12:  * Created by Microsoft Corp. 1986
1.1       root       13:  */
                     14: 
1.1.1.2 ! root       15: #define INCL_DOSDATETIME
        !            16: 
        !            17: #include  <os2def.h>
        !            18: #include  <bsedos.h>
1.1       root       19: 
                     20: main()
                     21: {
1.1.1.2 ! root       22:     DATETIME curdt, newdt, setdt;
1.1       root       23: 
                     24:     /* Read current date and time */
1.1.1.2 ! root       25:     DosGetDateTime(&curdt);
1.1       root       26: 
                     27:     /* Print date and time */
                     28:     printf("TIME: %d:%02d:%02d.%02d  DATE: %d/%d/%d  DAY OF WEEK: %d\n",
1.1.1.2 ! root       29:        curdt.hours,curdt.minutes,curdt.seconds,curdt.hundredths,
        !            30:        curdt.month,curdt.day,curdt.year,curdt.weekday);
1.1       root       31:     /* NOTE: the system sets the 'timezone' value to -1 by default */
                     32:     printf("GMT = local_time %+d minutes\n",curdt.timezone);
                     33: 
                     34: 
                     35:     /* Set datetime struct to Thursday 12/25/86, 9:02:45.01pm PST */
1.1.1.2 ! root       36:     setdt.hours        =   21; /* Time is in 24 hour format */
1.1       root       37:     setdt.minutes       =    2;
                     38:     setdt.seconds       =   45;
                     39:     setdt.hundredths    =    1;
                     40:     setdt.day           =   25;
                     41:     setdt.month         =   12;
                     42:     setdt.year          = 1986; /* Year should include the century */
                     43:     setdt.timezone      =  480; /* PST is 8 hours after GMT (480 minutes) */
                     44: 
                     45:     /* Set system date and time */
1.1.1.2 ! root       46:     DosSetDateTime(&setdt);
1.1       root       47: 
                     48:     /* Read new date and time just set */
1.1.1.2 ! root       49:     DosGetDateTime(&newdt);
1.1       root       50: 
                     51:     /* Print date and time */
                     52:     printf("TIME: %d:%02d:%02d.%02d  DATE: %d/%d/%d  DAY OF WEEK: %d\n",
1.1.1.2 ! root       53:        newdt.hours,newdt.minutes,newdt.seconds,newdt.hundredths,
        !            54:        newdt.month,newdt.day,newdt.year,newdt.weekday);
1.1       root       55:     printf("GMT = local_time %+d minutes\n",newdt.timezone);
                     56: 
                     57:     /* Reset date and time to whatever was read at the beginning */
1.1.1.2 ! root       58:     DosSetDateTime(&curdt);
1.1       root       59: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.