Loop doesn’t work

This should work (if your post_type is not post you will need to amend the code)

<?php
$args = array(
'post_type' => 'post',
'cat'  => '31',
'posts_per_page' => 5,
);

$query = new WP_Query( $args );?>

    <?php if( $query->have_posts() ) : ?>

    <?php while( $query->have_posts() ) : $query->the_post(); ?>    

    <li><a href="https://wordpress.stackexchange.com/questions/209558/<?php the_permalink(); ?>"><i class="fa fa-book"></i> <?php the_title(); ?></a> <span>Di <?php the_author(); ?>, <?php the_time('d/m/Y'); ?></span></li>

<?php

endwhile;
endif;
// Reset Query
wp_reset_query();
?>