![]() |
|
||||||||||||||
| | 网站首页 | 技术教程 | 网站开发 | 程序下载 | 言情小说 | 法律咨询 | Firefox | 两性故事 | 健康知识 | 网络游戏 | 免费论文 | | ||
|
||
|
|||||
| UNIX环境下的日期程序 | |||||
|
前段时间做了一个计费程序,其中涉及到有关日期与时间的计算,如求某日某时的前(或后)一段时间是什么时候,UNIX C系统本身并未提供此类函数,笔者经摸索,设计了一个求时间的函数,现介绍给大家。 功能介绍与参数说明 参数说明如下: s:为给定的日期时间,如2001年6月2日18点30分04秒为“20010602183004”; bill_long:给定的时间长度,单位为秒; d_str:求出的日期,如2001年6月2日为“20010602”; t_str:求出的时间,如18点28分06秒为“182806”; 函数返回值为星期,如星期日为0,星期一至六分别对应1~6。 实现代码 int GetDateTime( char s,long int bill_long,chard_str, char t_str) { time_t timer,tim ; struct tm tb, tb1 ; int year_off = 1900 ; int mon_off = 1 ; char s1[20] ; if ( strlen( s )!=14 ) return -1; strncpy( s1, s, 4 ); s1[4] = '\0' ; tb.tm_year = atoi( s1 ); strncpy( s1, s+4, 2 ); s1[2] = '\0' ; tb.tm_mon = atoi( s1 ); strncpy( s1, s+6, 2 ); s1[2] = '\0' ; tb.tm_mday = atoi( s1 ); if ( tb.tm_year==0 || tb.tm_mon==0 ||tb.tm_mday==0 ) return -1; strncpy( s1, s+8, 2 ); s1[2] = '\0' ; tb.tm_hour = atoi( s1 ); strncpy( s1, s+10, 2 ); s1[2] = '\0' ; tb.tm_min = atoi( s1 ); strncpy( s1, s+12, 2 ); s1[2] = '\0' ; tb.tm_sec = atoi( s1 ); tb.tm_year -= year_off ; tb.tm_mon -= mon_off ; tb.tm_isdst = 0 ; tim=mktime( &tb ) ; tim=tim-bill_long; tb1=localtime(&tim); sprintf(d_str, "%#04d%#02d%#02d",1900+tb1->tm_year,tb1->tm_mon+1,tb1->tm_mday); sprintf(t_str, "%#02d%#02d%#02d",tb1->tm_hour, tb1->tm_min,tb1->tm_sec); return (tb1->tm_wday); } / end of GetDateTime / |
|||||
| 【发表评论】【加入收藏】【告诉好友】【打印此文】【关闭窗口】 | |||||
| 最新热点 | 最新推荐 | 相关文章 | ||
| “自启动”程序搜索大法 真正地隐藏文件和禁止使用文 SCO UNIX系统“root密码”丢 Windows死机密码 巧设无软驱电脑 Windows安装备忘录 Windows 里的备用鼠标 快速重启电脑 电脑诊治之Windows故障详解( 电脑诊治之Windows故障详解( |
| 网友评论:(只显示最新10条。评论内容只代表网友观点,与本站立场无关!) |
| | 设为首页 | 加入收藏 | 联系站长 | 友情链接 | 网站地图 | Baidu News | Google Map | | |||
|