z390 Portable Mainframe Assembler and Emulator

Standard Timestamp Support for
Assembler, C, COBOL, Java, SQL, XML

Automated Software Tools Corporation

Overview ot Timestamps

Timestamps are used in most computer systems to define the date and or time associated with an event or transaction.  There are several standards for defining date and time but they are not consistently followed so every computer platform, operating system, and language has different formats and methods for processing date and time information.  Perhaps the closest thing to a consistent standard is the ISO 8601 standard for external date amd time which simply says the sequence should be 4 digit year, month, day, hour, minute, and second so the timestamps can be compared and sorted easily.  The year, month, and day typically refer to the Gregorian Calender which is the most widely used and is the defacto standard.  To simplify date calculations and time interval measurement, timestamps are often stored as a single numeric number with 0 representing some local time zone arbitrary starting time called an epoch.  There are many different date and time epochs in use today including:

For 32 bit computer systems that count seconds from the epoch January 1, 1970 such as some Unix and Linux systems, the counter will overflow in the year 2038 potentially causing another Y2K type event unless these systems are converted to use 64 bit counters or the epoch is moved forward to delay the inevitable.  For those interested in a standard Univeral Time for planet earth, there is GMT (also called UTC or UT1).  For geologists there is geological time starting about 5 billion years ago.  Then for those interested in a truly universal time scale, consider joining SETI (one of the worlds largest distributed processing grid projects to detect extra terrestrials intelligence) and get ready to redefine "Universal Time" when we discover a plant that has its own universal time starting perhaps 10 billion years ago.  Calling earth time as "Universal" is like declaring the earth as the center of the universe.

Moving from the galactic scale down to the sub second scale, timestamps are also often used to to uniquely identify events within a computer system.  And as the speed of computer chips continue to increase with cycle times exceeding GHZ, there is a need for more precise timestamps measuring microseconds and nanoseconds.  The z390 version of the IBM mainframe compatible TIME macro has added a new time NS which returns a 64 bit value representing the nanoseconds since the J2SE Java runtime startup.  This function uses System.nanotime() class method which in turn for Windows host operating systems uses the QueryPerformanceFrequency and QueryPerformanceCounter functions for measuring short intervals.  A similar approach has been used recently to add a Micro Focus Mainframe Express COBOL callable routine named GETTIME that returns the current date and time in microseconds using the Windows January 1, 1601 epoch and the additional function GetSystemTimeAsFileTime.  This COBOL function  is available from Micro Focus for customer use.  There are similar functions in C, Java, SQL, XML and other languages but they are all different enough that a change in platform, operating system, or language vendor will probably require conversion.  Have you noticed that almost every computer installation has its own set of callable date and time routines that have evolved for the years and are ofter written in assembler?


Mainframe Assembler Timestamp Support

Both IBM z/OS and z390 Mainframe Assembler languages support the TIME macro to retrieve date and time in verious formats.   z390 has added the following extensions to its TIME macro:
  1.  TIME TS,ADDR=timestamp returns 29 character EBCDIC timestamp in the following format:
       YYYY-MM-DD HH:MM:SS.NNNNNNNNN WHERE NNNNNNNNN is in nanoseconds.  This is the same
       format as JDBC SQL timestamp.
 2.  TIME NS returns nanosecond counter for use in interval measurements in 64 bit GPR 0.
 3.  CLOCK=JAVA returns time since J2SE epoch Jan. 1, 1970 versus default IBM epoch Jan. 1, 1900.  (Note Windows system uses epoch Jan 1, 1601 and Linux system uses the same epoch as J2SE Jan. 1, 1970.)


C Timestamp Support

Linux supports several date and time functions including ftime(time) returning 2 64 bit fields containing seconds since
the epoch Jan. 1, 1970 and microsecond fraction of a second.

Windows WIN32API includes the following calls:
  1.  GetSystemTimeAsFileTime() - returns 64 bit time in 100 nanoseconds since epoch Jan 1, 1601.  This is the format
       to timestamp files in Windows.
  2.  QueryPerformanceFrequency() - returns 64 bit frequency of updates for QueryPerformanceCounter.
  3.  QueryPerformanceCounter() - returns 64 bit counter incremented QueryPerformanceFrequ


COBOL Timestamp Support

The COBOL standards support obtaining date and time in numerous formats using intrinsic functions and ACCEPT options.  For comprehensive lists see:  http://www.cobolstandard.info/j4/files/05-0094.doc

Unfortunately  there does not appear to be a consistent standard COBOL method to obtain time of day in microseconds or nanoseconds for more precise interval timing.  As a result calls to functions written in C or assembler are often used to obtain such time formats.

For Micro Focus Mainframe Express COBOL running on Windows, there is now a subroutine written in COBOL which uses the WIN32API interface to the Windows time functions to obtain the time of day in microseconds.  This routine is available to Micro Focus customers.


IBM, CICS, HLASM, MVS, OS/390, VSAM, z9, z10, and z/OS
 are registered trademarks  of International Business Machines Corporation

This page last updated Sunday September 07, 2008.   Webmaster 
Copyright 2008 Automated Software Tools Corporation