
如何用c++将一个时间点转换成时间戳
时间戳转格式化。
时间戳转格式化。
格式化转时间戳。
ystemTimeToVariantTime。VariantTimeToSystemTime。
VariantTime是个double类型,单位是天,很便于计算。
SYSTEMTIME是包含年月日时分秒毫秒的一个结构体,便于分析处理。
#include<stdioh>#include<time.h>int main(int argc, const char * argv[{time_t t;struct tm *p。
t=1384936600;p=gmtime(&t)char s[100];strftime(s, sizeof(s), "%Y%m%d %H:%M:%S", p);printf("%d%s\n", (int)t, s);return 0。
#include<stdio.h>#include <time.h>int main(int argcconst char * argv[{struct tm* tmp_time = (struct tm*)malloc(sizeof(struct tm));strptime("20131120","%Y%m%dtmp_time);time_t t = mktime(tmp_time);printf("%ld\n",t),free(tmp_time)return 0}。
时间戳转格式化
#include <stdio.h>
#include <time.h>
int main(int argc, const char * argv[])
{
time_t t;
struct tm *p;
t=1384936600;
p=gmtime(&t);
char s[100];
strftime(s, sizeof(s), "%Y-%m-%d %H:%M:%S", p);
printf("%d: %s\n", (int)t, s);
return 0;
}
格式化转时间戳
#include <stdio.h>
#include <time.h>
int main(int argc, const char * argv[])
{
struct tm* tmp_time = (struct tm*)malloc(sizeof(struct tm));
strptime("20131120","%Y%m%d",tmp_time);
time_t t = mktime(tmp_time);
printf("%ld\n",t);
free(tmp_time);
return 0;
}

2016-07-20