如何在 C 中用零填充空白(整数)位置?

How to fill in blank (integer) places with zero in C?

我想在 C 整数中添加前导零。我正在做一个时钟。这是我目前的代码:

int main(){

    while (1){
    time_t present;
    time(&present);
    struct tm *myTime =  localtime(&present);
    printf("%2d:%2d:%2d\n", myTime->tm_hour,myTime->tm_min, myTime->tm_sec);
    sleep(1);
    }

    return 0;
}

这是当前输出:

11:30: 0
11:30: 1
11:30: 2
11:30: 3
11:30: 4
11:30: 5
11:30: 6
11:30: 7
11:30: 8
11:30: 9
11:30:10

这是我想要的输出:

11:30:00
11:30:01
11:30:02
//and so on...

% 和长度修饰符之间填充一个 0,此处 2,在 printf() 调用中的每个格式说明符处:

printf("%02d:%02d:%02d\n", myTime->tm_hour,myTime->tm_min, myTime->tm_sec);
         |    |    |
        here here here