Tag: 时间

使用时间函数的链接列表打印错误

打印时间戳时程序崩溃。 我相信错误位于函数void flightRec_PrflightRecData(flightRecRead * thisFlight)中,它旨在做三件事: 声明时间结构的飞行时间,飞行时间是POSIX格式。 Localtime将POSIX时间转换为人类可读的时间。 第四个说明符使用asctime打印转换时间,该时间以Www Mmm dd hh:mm:ss yyyy格式打印。 错误是tb!= NULL并显示指定asctime的其他信息。 我做了什么来排除故障: 检查时间标题 检查指针和地址 关闭了弃用 检查格式说明符 任何帮助表示赞赏。 #include #include #include #include typedef struct flightRec_struct { // declare a struct to match the format of the binary data char FlightNum[7]; char OriginAirportCode[5]; char DestAirportCode[5]; int timestamp; } flightRec; typedef struct flightRecRead_struct { // […]

减去两个时间间隔

我想减去两个时间间隔。 这里一个时间间隔是5小时30分钟,其他是当前时间。代码写成如下。 main() { int Time1; int Time2; int hour=10; int minute=5; int second=13; int h; int m; int Ntime; Time1=(60*5)+(30); Time2=60*hour+minute; Ntime=Time2-Time1; m=(Ntime%60); Ntime=Ntime/60; h=(int)(Ntime); printf(“hour after subtraction is : %d hour %d min”,h,m) }

将毫秒转换为分钟

如何在Objective-C或C中将毫秒转换为分钟或小时?

如何测量C中每个线程的时间?

我正在研究具有多个线程的代码,我想打印完成任务所花费的时间,我分配了第i个线程。 含义我想打印每个线程使用doSomeThing函数完成的时间 int main(int argc, char *argv[]){ // … i=0; while (i < NumberOfThreads){ check = pthread_create(&(id_arr[i]), NULL, &doSomeThing, &data); i++; } // … } void* doSomeThing(void *arg){ // … } 如果我在pthread_create之前添加gettimeofday(&thread_start, NULL)然后在pthread_create之后添加gettimeofday(&thread_end, NULL) ,我实际上会测量每个线程花费的时间还是主要花费的时间? 如果我把gettimeofday放在doSomething函数中,它们不会创建竞争条件吗? 如果您对如何测量每个线程的时间有任何想法,请告诉我,谢谢。

测试C代码中的SEGV在ARM Cortex M4处理器中经过的时间内出错

我正在为我的stm32f429板编写嵌入式操作系统的代码。 我正在测试此代码的使用时间: #include #include #include #include #include #include #define DEFAULT_DELAY 1 uint32_t m_nStart; //DEBUG Stopwatch start cycle counter value uint32_t m_nStop; //DEBUG Stopwatch stop cycle counter value #define DEMCR_TRCENA 0x01000000 /* Core Debug registers */ #define DEMCR (*((volatile uint32_t *)0xE000EDFC)) #define DWT_CTRL (*(volatile uint32_t *)0xE0001000) #define CYCCNTENA (1<= ticks) break; } } uint32_t CalcNanosecondsFromStopwatch(uint32_t nStart, […]

在c中将字符串转换为时间格式

假设我有一个字符串“2011-08-21 21:48:45 +1200”,另一个格式相同, 我想比较这两个字符串,找出哪一个是早期的或后一个, 有没有一种简单的方法将字符串转换为时间格式而不是按字符进行比较? 谢谢

C初学者编程帮助日历代码更新

实现打印给定月份和年份的日历的function。 首先,提示用户: 输入月份和年份: 一旦用户输入有效输入(由空格分隔的两个整数),以与UNIX cal命令的输出类似的格式打印日历。 例如,如果用户输入03 2014,则输出应为: View post on imgur.com 我的代码的更新版本,对于stackflow的新缩进感到抱歉,它不会让我只是复制并粘贴我的代码说我有缩进问题: #include int main(){ int year; int month, day; int days_in_month[]={0,31,28,31,30,31,30,31,31,30,31,30,31}; char *months[]= { ” “, ” January”, ” February”, ” March”, ” April”, ” May”, ” June”, ” July”, ” August”, ” September”, ” October”, ” November”, ” December” }; printf(“Please enter a […]

mktime显示输出不一致

在尝试编写比给定时间少24小时的代码时, mktime()显示输出不一致。 我计算它类似于: current_time(GMT) – 86400 ,它应该返回正确的值。 我们需要做的就是根据输入时间计算; 我们使用mktime()来改变时间并获得GMT时间,然后进行常规计算。 我在下面提供了我的代码。 #include #include int main() { time_t currentTime, tempTime; struct tm *localTime; time(&currentTime); //localTime = localtime(&currentTime); localTime = gmtime(&currentTime); //get the time in GMT as we are in PDT printf(“Time %2d:%02d\n”, (localTime->tm_hour)%24, localTime->tm_min); localTime->tm_hour = 19; // Set the time to 19:00 GMT localTime->tm_min = 0; […]

通过恒定长度遍历数组的访问时间

我想测量缓存的速度(我问了一个问题 ),所以我写了这段代码: #include #include #include const int mod = 100000007; volatile int f[100000007]; volatile int *p; int main() { FILE *f1; f1=fopen(“CacheTest.txt”,”w”); for(int l=1;l<=100000;) { clock_t st,ed; st=clock(); int now=0; for(int i=0;i=mod) now-=mod; } ed=clock(); double extime=(double)(ed-st)/CLOCKS_PER_SEC; st=clock(); now=0; for(int i=0;i=mod) now-=mod; } ed=clock(); double cost=(double)(ed-st)/CLOCKS_PER_SEC; fprintf(f1,”length %d costs %f seconds access time:%f\n”,l,cost,cost-extime); printf(“length %d […]

我使用tm / mktime是错误的,如果没有,是否有解决方法?

我认为以下程序应该从每年的第一天输出从1970年到1970年的秒数,然后是它编译的系统上的time_t的大小( CHAR_BIT是一个宏,所以我认为你不能只复制编译可执行文件并假设它是正确的虽然在实践中一切都使用8位char这些天)。 #include #include #include #include #include void do_time(int year) { time_t utc; struct tm tp; memset(&tp, 0, sizeof(tp)); tp.tm_sec = 0; tp.tm_min = 0; tp.tm_hour = 0; tp.tm_mday = 1; tp.tm_mon = 0; tp.tm_year = year – 1900; tp.tm_wday = 1; tp.tm_yday = 0; tp.tm_isdst = -1; printf(“%d %ld\n”,year, mktime(&tp)); } int main(){ printf(“time_t […]