1752781 Members
6192 Online
108789 Solutions
New Discussion юеВ

Re: OPEN VMS C

 
Rizwan Latheef
Occasional Contributor

OPEN VMS C

How to printf system time time in OPEN VMS C
5 REPLIES 5
Martin Vorlaender
Honored Contributor

Re: OPEN VMS C

You can either use ANSI C functions. like

time_t t = time((time_t)9); printf(asctime(localtime(&t)));

Or you set up a $DESCRIPTOR and call SYS$ASCTIM().

cu,
Martin
Craig A Berry
Honored Contributor

Re: OPEN VMS C

There is an exmple of calling lib$sys_asctim here:

http://www.eight-cubed.com/examples/framework.php?file=lib_sys_asctim.c
Martin Vorlaender
Honored Contributor

Re: OPEN VMS C

...and an example for SYS$ASCTIM here:

http://www.eight-cubed.com/examples/framework.php?file=sys_asctim.c

As much as I prefer LIB$ routines when it comes to not using itemlists for just one item to retrieve, in this case and IMHO, $ASCTIM is easier to use.
Claus Olesen
Advisor

Re: OPEN VMS C

here's another alternative. the order of year and day is the correct one ihmo.
char *timestamp(char *timestamp)
{
int n;
int csec; //centisecs
struct timeval tv;
struct tm *ptm;

gettimeofday(&tv,NULL);
ptm=localtime(&tv.tv_sec);
n=strftime(timestamp,20,"%Y-%m-%d %H:%M:%S",ptm);
csec=tv.tv_usec/10000;
sprintf(timestamp+n,".%2.2d",csec);
return timestamp;
}

here's a hack. with the year and day in the other order.
int szTime[8] = {23,(int)(szTime+2),0};
lib$date_time(szTime);
printf("%s\n",(char*)(szTime+2));

Hoff
Honored Contributor

Re: OPEN VMS C

>>> How to printf system time time in OPEN VMS C? <<<

Um, the same way you issue a printf for the system time in every other C implementation? This from K&R C forward through to the ANSI C and POSIX C calls and C99.

Others have addressed the direct C coding question.

I'm going to guess that you're wondering about the C/Unix epoch -- which is the same on OpenVMS as implemented on most (all?) other C platforms -- and the use of the native quadword time format, and UTC timekeeping.

I'd tend to use either the C/Unix epoch or the UTC calls if you're working in new code. Which depends on your particular goals and needs.

There are details on time and timekeeping in the OpenVMS FAQ (www.hoffmanlabs.com) and in the C RTL manual (www.hp.com/go/openvms/doc) with the newest C RTL manual now located in the main OpenVMS manual set and not in the C manual shelf.