11/13位时间戳转化为标准时间
来源:互联网 发布:杂志排版用什么软件 编辑:程序博客网 时间:2024/05/16 07:46
// TimeConvert.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <time.h>#include <string.h>int IsLeap(unsigned short year){return ((year%4==0)&&(year%100!=0)||(year%400==0));}void MillSecond2LocalTime(long long time,long timezone){const int monthLengths[2][13]={{0,31,59,90,120,151,181,212,243,273,304,334,365},{0,31,60,91,121,152,182,213,244,274,305,335,366}};const int yearLengths[2]={365,366};int year(0),month(0),minMonth(0),maxMonth(0),days(0),clock(0),isLeap(0),day(0),hour(0),minute(0),second(0);time/=1000;time+=timezone*60*60;days=time/86400;//天数clock=time%86400;//小时数if(clock<0){clock+=86400;days-=1;}if(days>=0){year=days/366;days-=year*365+(year+1)/4-(year+69)/100+(year+369)/400;for (year=year+1970;;year++){isLeap=IsLeap(year);if(days<yearLengths[isLeap]){break;}days-=yearLengths[isLeap];}}else{year=days/366;days-=year*365+(year-2)/4-(year-30)/100+(year-30)/400;for(year=year+1970-1;;year--){isLeap=false;days+=yearLengths[isLeap];if (days>=0){break;}}}minMonth=0;maxMonth=12;for (month=5;month<12&&month>0;month=(minMonth+maxMonth)/2){if (days<monthLengths[isLeap][month]){maxMonth=month;}else if (days>=monthLengths[isLeap][month+1]){minMonth=month;}else{break;}}days-=monthLengths[isLeap][month];month++;day=days+1;hour=clock/3600;clock=clock%3600;minute=clock/60;second=clock%60;printf("%d-%02d-%02d %02d:%02d:%02d",year,month,day,hour,minute,second);}int main(int argc, char* argv[]){char *str="402395506223";long long time;sscanf(str,"%I64d",&time);MillSecond2LocalTime(time,8);}
方法2 :使用结构体 tm
void main() { struct tm *newtime; char tmpbuf[128]; time_t lt; lt=time( NULL ); newtime=localtime(<); printf("%d 月 %d 日 %d 点 %d 分 %d 秒\n",newtime->tm_mon+1, newtime->tm_mday,newtime->tm_hour,newtime->tm_min,newtime->tm_sec); }
0 0
- 11/13位时间戳转化为标准时间
- IOS如何将获取的13位时间戳转化为标准时间
- 时间戳转化为标准时间
- js将标准时间格式转化为时间戳
- iOS将标准时间转化为时间戳
- js中如何把时间戳转化为标准时间
- js时间戳转化为标准时间的方法
- iOS 时间戳转化为时间(附13位转10位方法)
- iOS 时间戳转化为时间(附13位转10位方法)
- 13/11位unix时间戳转换成标准时间
- 数据库中10位或13位时间戳转换为标准时间
- 时间戳转化为时间
- 时间戳转化为时间
- json传出的时间戳转化为标准格式
- iOS将字符串转化为标准时间
- 13位时间戳转化北京时间
- .net18位时间戳转化为java Date对象
- mongoose时间自动转化为格林尼治标准时间的解决方案
- apache kafka系列之broker内部架构
- 在VS2010中ActiveX控件注册方法,使用regsvr32命令
- arm9-rtos的中断汇编代码分析helper2416-rawos
- oracle表空间增加问题
- uva 10542 - Hyper-drive(容斥)
- 11/13位时间戳转化为标准时间
- ZOJ-1261
- BZOJ 1646: [Usaco2007 Open]Catch That Cow 抓住那只牛
- Android 中电源状态切换
- IF语句的介绍
- 链表操作————合并两个链表,并同时删除两链表中的公共元素结点
- hdu-1753-大明A+B
- Xenix杂谈
- WampServer php运行环境一键安装