300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > 用时间戳判断两个时间是否在同一天和时区转换问题

用时间戳判断两个时间是否在同一天和时区转换问题

时间:2021-12-03 12:20:50

相关推荐

用时间戳判断两个时间是否在同一天和时区转换问题

用时间戳判断两个时间是否在同一天和时区转换问题

//用时间戳判断两个时间是否在同一天和时区转换问题#include "stdafx.h"#include<stdio.h>#include<time.h>#include<stdlib.h>#pragma warning(disable:4996)//是否开启DEBUG模式#define _DEBUG_ 1#if _DEBUG_#define ACCLOG(...) printf(__VA_ARGS__)#else#define ACCLOG(...)#endif//检验是否过期int check_day(){//myTime:1526537851//userTime:1526488911char userTime[11] = "1526488911";//从二维码扫到的时间戳,/5/17 0:41:51//char myTime[11] = "1526537851";//硬件保存的时间戳(解密后) ,/5/17 14:17:31char myTime[11] = "1526568851"; ///5/17 22:54:11time_t t1, t2;struct tm *p1, *p2;char date1[9] = "";char h1[3] = "";t1 = atoi(myTime) + 28000;//time(&t1);p1 = gmtime(&t1);ACCLOG("myTime:%s\n", myTime);strftime(date1, sizeof(date1), "%Y%m%d", p1);strftime(h1, sizeof(h1), "%H", p1);char date2[9] = "";char h2[3] = "";t2 = atoi(userTime) + 28000;//time(&t2);p2 = gmtime(&t2);strftime(date2, sizeof(date2), "%Y%m%d", p2);strftime(h2, sizeof(h2), "%H", p2);ACCLOG("userTime:%s\n", userTime);ACCLOG("date1:%s\ndate2:%s\nh1:%s\nh2:%s\n", date1, date2, h1, h2);//打印本地时间time_t rawtime;struct tm * timeinfo;char buffer[128];time(&rawtime);printf("%ld\n", rawtime);timeinfo = localtime(&rawtime);strftime(buffer, sizeof(buffer), "Now is %Y/%m/%d %H:%M:%S", timeinfo);ACCLOG("%s\n", buffer);if (atoi(date1) == atoi(date2) && atoi(h1) +8 <= 23)如果给myTime时间戳加了28000秒(8H)这里就不用加8H了{printf("时间在开门范围内,去判断密码是否正确\n");return 1;}else {printf("时间不在范围内\n");return 0;}}//myTime:1526466422/5/16 18:27:2//userTime:1526422882 /5/16 6:21:22int main(void){if (check_day() == 1){ACCLOG("check_password............\n");}else{ACCLOG("time is over...\n");}getchar();return 0;}

结果:

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。