Do you just want this lines ?
$midnight_time = strtotime('tomorrow') - time();
set_transient( 'transient_name', $transient_datas, $midnight_time);
$midnight_time
represent the seconds before midnight happens.
You can ask your server to curl a page with a random parameter if you have cache to be sure your transient is consumed with a cronjob
.