时钟计时器

 NSString *camera_clock;

    if (camera_clock == nil||![camera_clock containsString:@":"]||![camera_clock containsString:@"-"]) {

        return;

    }

    NSString *time = [camera_clock componentsSeparatedByString:@" "][1];

    NSString *date = [camera_clock componentsSeparatedByString:@" "][0];

    int timeT = [[time componentsSeparatedByString:@":"][0] intValue];

    int timeM = [[time componentsSeparatedByString:@":"][1] intValue];

    int timeS = [[time componentsSeparatedByString:@":"][2] intValue];

    int totalCount = timeT*60*60 + timeM*60 + timeS + 1;

    timeS = totalCount%60;

    timeM = totalCount%3600/60;

    timeT = totalCount/3600;

    int dateY = [[date componentsSeparatedByString:@"-"][0] intValue];

    int dateM = [[date componentsSeparatedByString:@"-"][1] intValue];

    int dateD = [[date componentsSeparatedByString:@"-"][2] intValue];

    

    if (timeT == 24) {

        timeT = 0;

        dateD += 1;

        if (dateD == 32) {

            dateD = 1;

            dateM += 1;

            if (dateM == 13) {

                dateM = 1;

                dateY += 1;

            }

        }else if(dateD == 31 && ((dateM == 4)||(dateM == 6)||(dateM == 9)||(dateM == 11))){

            dateD = 1;

            dateM += 1;

        }else if(dateD == 30 && dateM == 2){

            

            dateD = 1;

            dateM = 3;

        }else if(dateD == 29 && dateM == 2){

            if (dateY/4 != 0 || (dateY/400 != 0 && dateY/400 == 0)){

                dateM = 3;

                dateD = 1;

            }

        }

    }

    camera_clock = [NSString stringWithFormat:@"%d-%02d-%02d %02d:%02d:%02d",dateY,dateM,dateD,timeT,timeM,timeS];

posted @ 2018-04-24 14:25  象棋中的象棋  阅读(480)  评论(0编辑  收藏  举报