[3ae31e9] | 1 | /*
|
---|
| 2 | =============================================================================
|
---|
| 3 | now.c -- return the date and time as a string
|
---|
| 4 | Version 2 -- 1988-10-28 -- D.N. Lynx Crowe
|
---|
| 5 | (c) Copyright 1987, 1988 -- D.N. Lynx Crowe
|
---|
| 6 | =============================================================================
|
---|
| 7 | */
|
---|
| 8 |
|
---|
| 9 | #define TESTER 0 /* define non-zero to get a test program */
|
---|
| 10 |
|
---|
| 11 | #include "osbind.h"
|
---|
| 12 |
|
---|
| 13 | /*
|
---|
| 14 | =============================================================================
|
---|
| 15 | now(p) -- return the date and time as a string in 'p'
|
---|
| 16 |
|
---|
| 17 | Returns a pointer to the string provided, which must be at least
|
---|
| 18 | 21 bytes long. The string will be filled with the date and time
|
---|
| 19 | in the format:
|
---|
| 20 |
|
---|
| 21 | yyyy-mm-dd hh:mm:ss
|
---|
| 22 |
|
---|
| 23 | with a trailing zero byte.
|
---|
| 24 | =============================================================================
|
---|
| 25 | */
|
---|
| 26 |
|
---|
| 27 | char *
|
---|
| 28 | now(p)
|
---|
| 29 | char *p;
|
---|
| 30 | {
|
---|
| 31 | register long t;
|
---|
| 32 | short yr, mn, dy, hh, mm, ss;
|
---|
| 33 |
|
---|
| 34 | t = Gettime();
|
---|
| 35 |
|
---|
| 36 | yr = ((short)(t >> 25) & 0x007F) + 1980;
|
---|
| 37 | mn = (short)(t >> 21) & 0x000F;
|
---|
| 38 | dy = (short)(t >> 16) & 0x001F;
|
---|
| 39 |
|
---|
| 40 | hh = (short)(t >> 11) & 0x001F;
|
---|
| 41 | mm = (short)(t >> 5) & 0x003F;
|
---|
| 42 | ss = ((short)t & 0x001F) << 1;
|
---|
| 43 |
|
---|
| 44 | sprintf(p, "%4d-%02d-%02d %02d:%02d:%02d", yr, mn, dy, hh, mm, ss);
|
---|
| 45 |
|
---|
| 46 | return(p);
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | /* |
---|
| 50 |
|
---|
| 51 | */
|
---|
| 52 |
|
---|
| 53 | #if TESTER
|
---|
| 54 |
|
---|
| 55 | char x[22]; /* buffer for the returned string */
|
---|
| 56 |
|
---|
| 57 | /* simple test program for the now() function */
|
---|
| 58 |
|
---|
| 59 | main()
|
---|
| 60 | {
|
---|
| 61 | printf("Date/Time = %s\n", now(x));
|
---|
| 62 | exit(0);
|
---|
| 63 | }
|
---|
| 64 |
|
---|
| 65 | #endif
|
---|