首先要说的是,我在编程中是一个绝对的菜鸟,所以它可能是一个非常简单的事情,我没有得到它.
我想知道从一天开始以来已经过了多少时间,为此我使用了这个time()功能.
那么我想打印出来,这里是我的问题:与第一个printf变量seconds打印正确,但在第二个printf(其中我打印mills和seconds)它给了我一个错误的输出.
代码:
#include <stdio.h>
#include <time.h>
int main(void) {
long long int mills, seconds;
mills = time(NULL);
printf("Mills: %i\n", mills );
seconds = mills / 1000;
//here the variable is printed correctly
printf("Seconds: %i\n", seconds );
//here mills gets printed correctly but seconds gets printed as 0
printf("Milliseconds since midnight: %i\nSeconds since midnight: %i\n", mills, seconds);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
输出:
Mills: 1486143107
Seconds: 1486143
Milliseconds since midnight: 1486143107 …Run Code Online (Sandbox Code Playgroud)