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


The attached program 'calendar.cbl' uses OOP to return information about a passed date and the current time using the java.util.GregorianCalendar and other related classes.
You can compile and run it as follows:

   iscc calendar.cbl
   iscrun CALENDAR 
For instance, running the program with this command:
   iscrun CALENDAR 20230215
returns this information:
   Getting information for 20230215
   ERA: 1
   YEAR: 2023
   MONTH: 1
   WEEK_OF_YEAR: 7
   WEEK_OF_MONTH: 3
   DATE: 15
   DAY_OF_MONTH: 15
   DAY_OF_YEAR: 46
   DAY_OF_WEEK: 4
   DAY_OF_WEEK_IN_MONTH: 3

   Getting information for current time
   AM_PM: 0
   HOUR: 9
   HOUR_OF_DAY: 9
   MINUTE: 40
   SECOND: 15
   MILLISECOND: 549
   ZONE_OFFSET: -8
   DST_OFFSET: 0
This program was based on the attached Java example, also found here: http://java.sun.com/javase/6/docs/api/java/util/GregorianCalendar.html

The DAY_OF_WEEK in the example above is '4', which means it's a Wednesday.

Another way to get the text of the day of the week is to use java.time classes.
You can compile and run this attached sample as follows:

   iscc day-of-week.cbl
   iscrun DAY_OF_WEEK 
The output for February 15, 2023 is WEDNESDAY.

Another way to work with the date and day is using isCOBOL and intrinsic functions.
Knowledge Base Article # 336 talks about how to manipulate dates using intrinsic functions.
The sample programs installed in $ISCOBOL/sample/is-java/iscobol-uses-cobol-object shows how to use these intrinsic functions in class-id programs, creating COBOL objects that can then be used in programs using OOP, similar to how the examples in this KB article use native Java objects.


Article ID: 119
Created: January 29, 2010
Last Updated: February 17, 2023
Author: Support KB Author

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