HP OpenVMS Systems

ask the wizard
Content starts here

OpenVMS Quadword Time Format?

» close window

The Question is:

 
I have binary data written to a file by a
VAX/VMS executable which includes a date field.  How do I convert the vax
 system time (which appears to be an 8-byte binary number) to a
unix epoch time, on (unfortunatly) another
platform?
 
 
 
 


The Answer is :

 
  Please ask the Wizard of the Target Platform how to convert the number
  of 100nanosecond intervals since the system base date of November 17,
  1858 00:00:00.00 (local time) -- this value is stored in a quadword --
  into the particular local time format required.
 
  The C epoch is the number of seconds since January 1, 1970 -- this value
  is stored in a C data cell with a typedef of time_t.
 
  If you choose to convert the time on OpenVMS, see the Compaq C RTL call
  decc$fix_time().  This call converts an OpenVMS binary system time
  (a 64-bit quadword containing the number of 100-nanosecond ticks since
  00:00 November 17, 1858) to a longword containing the number of seconds
  since 00:00 January 1, 1970, local time. To arrive to Unix time that
  can be passed to UTC-based ctime() or localtime() functions, call tzset()
  and add 'timezone' to the value returned by decc$fix_time().
 
---
#include {stdio.h}
#include {time.h}
#include {starlet.h}
 
main()
  {
  int vms_time[2];
  time_t local_time, UTC_time;
 
  /*
  //  Get the current time
  */
  sys$gettim(&vms_time[0]);
  UTC_time = time(NULL);
  local_time = decc$fix_time(vms_time);
  /*
  // local time cannnot be passed to UTC-based ctime()
  */
  puts(ctime(&local_time));
  /*
  //  Print the current time
  */
  puts(ctime(&UTC_time));
  tzset();
  local_time += timezone;
  /*
  //  Print current time
  */
  puts(ctime(&local_time));
  return 1;
  }
 

answer written or last revised on ( 6-FEB-2001 )

» close window