亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪(fǎng)問(wèn)板塊 發(fā)新帖
查看: 2335 | 回復(fù): 3
打印 上一主題 下一主題

關(guān)于時(shí)間操作的一些簡(jiǎn)單實(shí)現(xiàn) [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2006-07-25 20:25 |只看該作者 |倒序?yàn)g覽
本帖最后由 浪子雄心 于 2011-05-07 21:13 編輯

/*
**
** 文件: time.c
**
** 功    能:關(guān)于時(shí)間操作的一些簡(jiǎn)單實(shí)現(xiàn)
**
** 編譯及運(yùn)行:
** $cc -o time  -g -Wall time.c
** $./time
**
**
** 作  者:沒(méi)版權(quán),隨便用
**
** 說(shuō)明:本函數(shù)功能可以自由拷貝使用,
**      可能存在沒(méi)有發(fā)現(xiàn)在的Bug,
**      如有缺陷,還需使用者自行調(diào)試
*/

#include<stdio.h>
#include<stdlib.h>
#include<ctype.h>
#include<string.h>
#include<time.h>




/*
** 功能說(shuō)明:得到指定日期的后一天
** 輸入?yún)?shù):struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:0- 成功
*/
int getNextDay(struct tm *p){
        time_t timep;
        p->tm_sec=0;
        p->tm_min=0;
        p->tm_hour=0;
        timep = mktime(p)+24*60*60;
        p=localtime(&timep);
        return 0;
}


/*
** 功能說(shuō)明:是否為閏年
** 輸入?yún)?shù):struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:1-是  0- 否
*/
int isLeapYear(struct tm *p)
{
  return ((1900+p->tm_year) & 3) == 0 && ((1900+p->tm_year)%100 || \
          ((1900+p->tm_year)%400 == 0 && (1900+p->tm_year))) ?1 : 0;
}



/*
** 功能說(shuō)明:是否為年未
** 輸入?yún)?shù):struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:1- 是  0- 否
*/
int isYearEnd(struct tm *p){
        if( (11==p->tm_mon)&&(31== p->tm_mday)){
                return 1;
        }else{
                return 0;
        }
}



/*
** 功能說(shuō)明:是否為月未
** 輸入?yún)?shù):struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:1- 是  0- 否
*/
int isMonthEnd(struct tm *p){
        int Mday[]={31,28,31,30,31,30,31,31,30,31,30,31};

        if(1== p->tm_mon){
                Mday[p->tm_mon] += isLeapYear(p);
        }
        if(        p->tm_mday ==  Mday[p->tm_mon]){
                return 1;
        }else{
                return 0;
        }
}


/*
** 功能說(shuō)明:是否是周未(周六與周日)
** 輸入?yún)?shù):struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:1- 是  0- 否
*/
int isWeekEnd(struct tm *p){
        return((0==p->tm_wday)||(6==p->tm_wday))?1:0;
}


/*
** 功能說(shuō)明:從一個(gè)時(shí)間字符串 YYMMDD, YYYYMMDD,  
**                         YYYYMMDDHHMMSS,YY-MM-DD, YYYY-MM-DD,
**                        YY-MM-DD HH.MM.SS 
**                        找到對(duì)應(yīng)的日期并轉(zhuǎn)為 struct tm 結(jié)構(gòu)
** 輸入?yún)?shù):char *pos, struct tm *p
** 輸出參數(shù):int
** 返回值說(shuō)明:0 -成功  -1 -日期識(shí)別出錯(cuò)
*/
int find_date(char *pos, struct tm *p)
{
        int Mday[]={31,28,31,30,31,30,31,31,30,31,30,31};
        int length,value,vek[4];
        int flag=1*4+2*16;
        char *start,*k;
        k=pos;
        bzero((char*) vek,sizeof(int)*4);

        while (*pos && !isdigit(*pos))
                pos++;
        length=(int) strlen(pos);
        int i=0;
        for (i=0 ; i< 3; i++)
        {
                start=pos; value=0;
                while (isdigit(pos[0]) &&
                        ((pos-start) < 2 || ((pos-start) < 4 && length >= 8 &&
                                                                !(flag & 3))))
                {
                        value=value*10 + (int) (char) (*pos - '0');
                        pos++;
                }
                vek[flag & 3]=value; flag>>=2;
                while (*pos && (ispunct(*pos) || isspace(*pos)))
                        pos++;
        }

        char tmp[8];
        bzero(tmp,sizeof(tmp));
        sprintf(tmp,"%d",vek[0]);


        if ((4 > strlen(tmp))&&(vek[0] < 70)){
                vek[0]+= 2000;
        }else if(4 != strlen(tmp)){
        vek[0]+= 1900;
        }

        p->tm_year=vek[0]-1900;
        p->tm_mon=vek[1]-1;
        p->tm_mday=vek[2];
        p->tm_sec=0;
        p->tm_min=0;
        p->tm_hour=0;

        if( 0>vek[0] || vek[0]>9999){
                printf("time str: [%s]  Year err!\n",k);
                return -1;
        }

        if( 0>vek[1] || vek[1]>12){
                printf("time str: [%s]  Month [%d] err!\n",k ,vek[1]);
                return -1;
        }


        Mday[1]+=isLeapYear(p);

        if( 0>vek[2] || vek[2]>Mday[vek[1]-1]){
                printf("time str: [%s]  Day [%d] err!\n",k , vek[2]);
                return -1;
        }


        return 0;
}






int test(char *sTime){

        printf("\n");
        struct tm *p;
        time_t timep;
        time(&timep);
        p=localtime(&timep);
        printf(" 當(dāng)前日期 [%04d%02d%02d] \n", \
                (1900+p->tm_year),( 1+p->tm_mon), p->tm_mday);

        printf("被識(shí)別串為 [%s]\n",sTime);

        if(0 != find_date(sTime, p)){
                exit(0);
        };

        printf("日期識(shí)別為 [%04d%02d%02d]\n",1900+p->tm_year,1+p->tm_mon,p->tm_mday);
        getNextDay(p);
        printf("第二天日期 [%04d%02d%02d]\n",1900+p->tm_year,1+p->tm_mon,p->tm_mday);
        printf("是否為閏年 isLeapYear[%d]\n", isLeapYear(p));
        printf("是否是周末 isWeekend[%d] %d\n", p->tm_wday,isWeekEnd(p));

        printf("是否是月末 isMonthend[%04d%02d%02d] %d\n", \
                1900+p->tm_year,1+p->tm_mon,p->tm_mday, isMonthEnd(p));

        printf("是否是年末 isYearend[%04d%02d%02d] %d\n", \
                1900+p->tm_year,1+p->tm_mon,p->tm_mday, isYearEnd(p));
       
        printf("\n");

        return 0;
}






int main(){
/*
識(shí)別格式
YYMMDD,
YYYYMMDD,
YYYYMMDDHHMMSS,
YY-MM-DD,
YYYY-MM-DD,
YY-MM-DD HH.MM.SS
*/
        test("040528");
        test("20051230  12:21:12");
        test("20060227122112");
        test("06-02-28");
        test("2006-12-31");
        test("06-07-22 12.34.56");
        test("06-07-30 12.34.56");
        return 0;
}

[ 本帖最后由 浪子雄心 于 2006-7-26 16:47 編輯 ]

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2006-07-26 16:34 |只看該作者
不錯(cuò)的例子,學(xué)習(xí)下

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2006-07-27 09:45 |只看該作者
不錯(cuò)的東東。。。。
thanks for your shared...

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2007-06-01 19:44 |只看該作者
靜靜的走過(guò)。。
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專(zhuān)區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP