1.时间戳转格式化日期,比如:1384936600→ -11-20 08:36:40 输入一个long,输出一个nsstring
2.反过来:-11-20 08:36:40→1384936600 输入nsstring,输出一个long
好久没碰c语言。。好多函数都现查怎么用,还好一会就搞定了
1.时间戳转格式化日期
[cpp]view plaincopy#include<stdio.h>#include<time.h>intmain(intargc,constchar*argv[]){time_tt;structtm*p;t=1384936600;p=gmtime(&t);chars[100];strftime(s,sizeof(s),"%Y-%m-%d%H:%M:%S",p);printf("%d:%s\n",(int)t,s);return0;}
2.格式化日期转时间戳[cpp]view plaincopy#include<stdio.h>#include<time.h>intmain(intargc,constchar*argv[]){structtm*tmp_time=(structtm*)malloc(sizeof(structtm));strptime("1120","%Y%m%d",tmp_time);time_tt=mktime(tmp_time);printf("%ld\n",t);free(tmp_time);return0;}