c语言 时间 赋给 变量问题
# include<stdio.h># include <dos.h>
int main()
{
long i,j;
struct time t;
gettime(&t);
i=t.ti_hour;
j=t.ti_min;
printf("%2d %2d ",i,j);
return 0
}
输出i的值是对的,j的值一直为00.
我想获取当前分钟即(t.ti_min)的值给一个变量,
请问需要怎么做?
#include <stdio.h> #include <time.h> int main() { time_t t = time( NULL ); { // 本地时 struct tm* lt = localtime( &t ); printf( "%04d-%02d-%02d %02d-%02d-%02d\n", lt->tm_year+1900, lt->tm_mon+1, lt->tm_mday, lt->tm_hour, lt->tm_min, lt->tm_sec ); } { // 协调世界时 struct tm* gt = gmtime( &t ); printf( "%04d-%02d-%02d %02d-%02d-%02d\n", gt->tm_year+1900, gt->tm_mon+1, gt->tm_mday, gt->tm_hour, gt->tm_min, gt->tm_sec ); } return 0; }