Example of COBOL using Java classes to get date and time zone information


The attached program, calendar.cbl, shows how to use Java classes from COBOL to retrieve information about a date and the current time. The sample uses java.util.GregorianCalendar and related Java classes.

Compile and run the program as follows:

iscc calendar.cbl
iscrun CALENDAR <yyyymmdd>

For example:

iscrun CALENDAR 20230215

returns information including:

DAY_OF_WEEK: 4
TIME_ZONE: America/Los_Angeles
ZONE_OFFSET: -8
DST_OFFSET: 0

In this example, DAY_OF_WEEK is 4, which corresponds to Wednesday.

This COBOL sample was based on the Java GregorianCalendar example in the Java documentation here.

 Returning the Day Name

If you need the name of the day rather than the numeric value, you can use the Java java.time classes.

Compile and run the attached sample as follows:

iscc dayofweek.cbl
iscrun DAYOFWEEK <yyyymmdd>

For example:

iscrun DAYOFWEEK 20230215

returns:

WEDNESDAY

Using isCOBOL Intrinsic Functions

Java classes are not the only way to work with dates in isCOBOL.

Knowledge Base Article #336 describes how to manipulate dates using intrinsic functions.

You can also find examples in:

$ISCOBOL/sample/is-java/iscobol-uses-cobol-object

These samples show how intrinsic functions can be used in class-id programs to create COBOL objects that can then be used in object-oriented applications, similar to how the examples in this article use Java objects.



Article ID: 119
Created: January 29, 2010
Last Updated: November 17, 2026
Author: Support KB Author

Online URL: https://support.veryant.com/phpkb/article.php?id=119