DateTime in militaryformat

I am trying to get a time variable that always uses 4 digits to represent the time as per below.

I have tried the following

 string slotStartTimeInMilitaryFormat = $"{timeSlotsStartTime.Hour}{timeSlotsStartTime.Minute}";

Problem is that I need 1AM to be 0100 and 9PM to be 2100 in other words always a 4 digit representation of the time

but my code makes it 100 instead of 0100 etc.

How can I ensure I always get the 4 digit representation

0000 0030 0100

1300 1330 1400

Answer

Try…

string slotStartTimeInMilitaryFormat = timeSlotsStartTime.ToString("HHmm");