void getNowTime()
{
timespec time;
clock_gettime(CLOCK_REALTIME, &time); //获取相对于1970到现在的秒数
tm nowTime;
localtime_r(&time.tv_sec, &nowtime);
char current[1024];
sprintf(current, "dddd:d:d", nowTime.tm_year + 1900, nowTime.tm_mon, nowTime.tm_mday,
nowTime.tm_hour, nowTime.tm_min, nowTime.tm_sec);
}
#include<time.h> int clock_gettime(clockid_t clk_id,struct timespec *tp);
struct timespec
{
time_t tv_sec; /* 秒*/
long tv_nsec; /* 纳秒*/
};
#include <stdio.h>
#include <stddef.h>
#include <time.h>
int main(void)
{
time_t timer;//time_t就是long int 类型
struct tm *tblock;
timer = time(NULL);
tblock = localtime(&timer);
printf("Local time is: %sn", asctime(tblock));
return 0;
}
#include<time.h>
#include<stdio.h>
int main()
{
struct tm *t;
time_t tt;
time(&tt);
t = localtime(&tt);
printf("%4d年d月d日 d:d:dn", t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec);
return 0;
}
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
time_t tNow =time(NULL);
time_t tEnd = tNow + 1800;
//注意下面两行的区别
struct tm* ptm = localtime(&tNow);
struct tm* ptmEnd = localtime(&tEnd);
char szTmp[50] = {0};
strftime(szTmp,50,"%H:%M:%S",ptm);
char szEnd[50] = {0};
strftime(szEnd,50,"%H:%M:%S",ptmEnd);
printf("%s /n",szTmp);
printf("%s /n",szEnd);
system("PAUSE");
return EXIT_SUCCESS;
}
#include <cstdlib>
#include <iostream>
#include <time.h>
#include <stdio.h>
using namespace std;
int main(int argc, char *argv[])
{
time_t tNow =time(NULL);
time_t tEnd = tNow + 1800;
//在这里修改程序
//struct tm* ptm = localtime(&tNow);
//struct tm* ptmEnd = localtime(&tEnd);
struct tm ptm = { 0 };
struct tm ptmEnd = { 0 };
localtime_r(&tNow, &ptm);
localtime_r(&tEnd, &ptmEnd);
char szTmp[50] = {0};
strftime(szTmp,50,"%H:%M:%S",&ptm);
char szEnd[50] = {0};
strftime(szEnd,50,"%H:%M:%S",&ptmEnd);
printf("%s /n",szTmp);
printf("%s /n",szEnd);
system("PAUSE");
return EXIT_SUCCESS;
}
struct tm {
int tm_sec; /* 秒 – 取值区间为[0,59] */
int tm_min; /* 分 - 取值区间为[0,59] */
int tm_hour; /* 时 - 取值区间为[0,23] */
int tm_mday; /* 一个月中的日期 - 取值区间为[1,31] */
int tm_mon; /* 月份(从一月开始,0代表一月) - 取值区间为[0,11] */
int tm_year; /* 年份,其值等于实际年份减去1900 */
int tm_wday; /* 星期 – 取值区间为[0,6],其中0代表星期天,1代表星期一 */
int tm_yday; /* 从每年1月1日开始的天数– 取值区间[0,365],其中0代表1月1日 */
int tm_isdst; /* 夏令时标识符,夏令时tm_isdst为正;不实行夏令时tm_isdst为0 */
};
time_t now;
time(&now);// 等同于now = time(NULL)
printf("now time is %dn", now);
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有