How to change DateTime time format to military time format (Visual Cobol)?

In a managed COBOL program, I am using DateTime to insert time stamps, but I don't want the time format of HH:MM:SS AM; I want it in military time format with no AM or PM.  I have not been able to find out how to do this on the site.

Parents
  • "Managed COBOL" can mean COBOL for JVM or COBOL for .NET. When you ask a question about managed COBOL, please specify which variety you're talking about.

    For any question, it's a good idea to include the product name, version, and platform as well. We're not psychic.

    If you're talking about the .NET Framework's DateTime class (actually a structure, aka valuetype, not a class), that's a .NET Framework question, not a COBOL one. The answer is in the .NET Framework documentation:

    https://docs.microsoft.com/en-us/dotnet/api/system.datetime

    The Framework provides extensive support for formatting DateTime objects. You can format them directly to a string:

    declare timeNow = type DateTime::Now
    display timeNow::ToString("HH:mm:ss")

    Note the "HH" specifier gives you the hours using a 24-hour clock and two digits.

    Or you can specify a format for a DateTime object while doing composite formatting, e.g. with the String class Format method:

    display string::Format("It's {0:HH:mm:ss}", type DateTime::Now)

    There's a set of standard format specifiers, or you can use a custom format string as I've done here. Again, it's all in the .NET docs.

Reply
  • "Managed COBOL" can mean COBOL for JVM or COBOL for .NET. When you ask a question about managed COBOL, please specify which variety you're talking about.

    For any question, it's a good idea to include the product name, version, and platform as well. We're not psychic.

    If you're talking about the .NET Framework's DateTime class (actually a structure, aka valuetype, not a class), that's a .NET Framework question, not a COBOL one. The answer is in the .NET Framework documentation:

    https://docs.microsoft.com/en-us/dotnet/api/system.datetime

    The Framework provides extensive support for formatting DateTime objects. You can format them directly to a string:

    declare timeNow = type DateTime::Now
    display timeNow::ToString("HH:mm:ss")

    Note the "HH" specifier gives you the hours using a 24-hour clock and two digits.

    Or you can specify a format for a DateTime object while doing composite formatting, e.g. with the String class Format method:

    display string::Format("It's {0:HH:mm:ss}", type DateTime::Now)

    There's a set of standard format specifiers, or you can use a custom format string as I've done here. Again, it's all in the .NET docs.

Children
No Data