public static byte[] localDateTimeToS7DateTime(LocalDateTime data) {
        byte[] res = new byte[8];

        res[0] = byteToBcd((data.getYear() % 100));
        res[1] = byteToBcd(data.getMonthValue());
        res[2] = byteToBcd(data.getDayOfMonth());
        res[3] = byteToBcd(data.getHour());
        res[4] = byteToBcd(data.getMinute());
        res[5] = byteToBcd(data.getSecond());

        long ms = (long) (data.getNano() / 1_000_000);
        res[6] = (byte) ((int) (((ms / 100) << 4) | ((ms / 10) % 10)));
        //Java:1 (Monday) to 7 (Sunday)->S7:1 (Sunday) to 7 (Saturday)
        byte dayofweek = (byte) ((data.getDayOfWeek().getValue() < 7) ?
            data.getDayOfWeek().getValue() + 1 :
            (byte) 0x01);
        res[7] = (byte) (((ms % 10) << 4) | ((byte) (dayofweek)));

        return res;
    }
converts incoming Short to an integer regarding used BCD format

@param incomingShort the incoming byte
@return converted BCD number
plc4j/drivers/s7/src/main/java/org/apache/plc4x/java/s7/readwrite/utils/StaticHelper.java