示例#1
0
int DateClass::setMday(int day){
    if ((this->year != -1)&&(this->mon != -1)){
        if(validRange(sec,getNumberOfDaysInMonth(this->mon))){
            this->mday = day;
            return dateOk;
        }else{
            return badDay;
        }
    }else{
        return badDay;
    }
}
示例#2
0
void Date::setDate(int elapseTime)
{
	long seconds = elapseTime;
	long minutes = seconds / 60;
	long hours = minutes / 60;
	day = hours / 24;

	// Get year
	year = 1970;
	while (day >= (isLeapYear(year) ? 366 : 365))
	{
		day = day - (isLeapYear(year) ? 366 : 365);
		year++;
	}

	// get month
	month = 1;
	while (day >= getNumberOfDaysInMonth(year, month))
	{
		day = day - getNumberOfDaysInMonth(year, month);
		month++;
	}
}