这篇教程C++ year函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中year函数的典型用法代码示例。如果您正苦于以下问题:C++ year函数的具体用法?C++ year怎么用?C++ year使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了year函数的26个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: month void Date::add_month (int n) { // Negative if(n < 0) { int tmp = month(); this->m = tmp - abs(n) > 0 ? tmp - abs(n) : 12 - abs(n + tmp) % 12; if(n + tmp <= 0) { this->y -= (1 + floor(abs(n + tmp)/12)); } } else { int months = abs(n) + month(); if(months % 12 != 0) this->m = months % 12; else this->m = 12; if(months > 12 && months % 12 != 0) { this->y += months / 12; } else if (months > 12) { this->y += months / 12 - 1; } } if(!valid_date(year(), month(), day())) { this->d = days_this_month(); } this->julian_day_number = calc_julian_day_number(year(), month(), day()); }
开发者ID:Jacke20,项目名称:kth,代码行数:30,
示例2: days_this_month void Date::add_year (int n) { this->y += n; if(!valid_date(year(), month(), day())) { this->d = days_this_month(); } this->julian_day_number = calc_julian_day_number(year(), month(), day()); }
开发者ID:Jacke20,项目名称:kth,代码行数:7,
示例3: add_year Middle& Middle::add_year(int n) { if(n == 0) return *this; int sign = -1; if( n > 0) { sign = 1; } if(isLeapYear()) { if(std::abs(n) > 3 && isLeapYear(year() + 4*sign)) { _numeric += (365*4 + 1 )*sign; n -= sign * 4; return add_year(n); }else if((sign > 0 && (month() < 3 && !(month() == 2 && day() == 29 ))) || (sign < 0 && (month() > 2 || (month() == 2 && day() == 29 )))) { _numeric += 366 * sign; n -= sign; return add_year(n); } } else if(isLeapYear(year() + sign) && ((( month() > 2 || (month() == 2 && day() == 29 ))&& sign > 0) || (sign < 0 && (month() < 3 && !(month() == 2 && day() == 29 ))))) { _numeric += 366 * sign; n -= sign; return add_year(n); } _numeric += 365 * sign; n -= sign; return add_year(n); }
开发者ID:ViktorCollin,项目名称:cprog13,代码行数:29,
示例4: isValid// This method MUST be re-implemented in any new Calendar Systembool KCalendarSystem::isValid( int y, int month, int day ) const{ // Default to true Gregorian if ( y < year( earliestValidDate() ) || y > year( latestValidDate() ) ) { return false; } if ( month < 1 || month > 12 ) { return false; } if ( month == 2 ) { if ( isLeapYear( y ) ) { return ( day >= 1 && day <= 29 ); } else { return ( day >= 1 && day <= 28 ); } } if ( month == 4 || month == 6 || month == 9 || month == 11 ) { return ( day >= 1 && day <= 30 ); } return ( day >= 1 && day <= 31 );}
开发者ID:basilk87,项目名称:smc,代码行数:27,
示例5: formatStr//日期/时间字符串//length对于年份,=2则为短格式(如2004年则返回"04"),其余//数值则为4位字符串//对于其他日期/时间,=2则为固定两位字符串,(如1返回"01",//29返回"29"),其余数值则根据具体日期/时间返回1或2位字符串//因此只有length=2的情况才会有相应操作,其余均采用默认操作。LPCTSTR ringDateTime::year2str(int length/*=0*/){ if(length == 2) return formatStr(m_str,year()%100,length); else return formatStr(m_str,year(),0);}
开发者ID:tianjigezhu,项目名称:UI-Library,代码行数:13,
示例6: setYMD// Okint KCalendarSystemHebrew::daysInYear(const TQDate & date) const{ TQDate first, last; setYMD(first, year(date), 1, 1); // 1 Tishrey setYMD(last, year(date) + 1, 1, 1); // 1 Tishrey the year later return first.daysTo(last);}
开发者ID:Fat-Zer,项目名称:tdelibs,代码行数:9,
示例7: BOOST_FORCEINLINE Date operator >(month_day md, Date d) { Date res; if (res.set_if_valid_date(year(d),month(md),day(md)) && res > d ) return res; if (res.set_if_valid_date(year(year(d)+1),month(md),day(md)) && res > d ) return res; res=Date(year(year(d)+2),month(md),day(md)); return res; }
开发者ID:arunk-s,项目名称:chrono_date,代码行数:9,
示例8: locIsDST/*----------------------------------------------------------------------* * Determine whether the given Local time_t is within the DST interval * * or the Standard time interval. * *----------------------------------------------------------------------*/boolean Timezone::locIsDST(time_t local){ //recalculate the time change points if needed if (year(local) != year(_dstLoc)) calcTimeChanges(year(local)); if (_stdLoc > _dstLoc) //northern hemisphere return (local >= _dstLoc && local < _stdLoc); else //southern hemisphere return !(local >= _stdLoc && local < _dstLoc);}
开发者ID:benny0924,项目名称:Timezone,代码行数:14,
示例9: toLocal/*----------------------------------------------------------------------* * Convert the given UTC time to local time, standard or * * daylight time, as appropriate. * *----------------------------------------------------------------------*/time_t Timezone::toLocal(time_t utc){ //recalculate the time change points if needed if (year(utc) != year(_dstUTC)) calcTimeChanges(year(utc)); if (utcIsDST(utc)) return utc + _dst.offset * SECS_PER_MIN; else return utc + _std.offset * SECS_PER_MIN;}
开发者ID:benny0924,项目名称:Timezone,代码行数:14,
示例10: toUTC/*----------------------------------------------------------------------* * Convert the given local time to UTC time. * * * * WARNING: * * This function is provided for completeness, but should seldom be * * needed and should be used sparingly and carefully. * * * * Ambiguous situations occur after the Standard-to-DST and the * * DST-to-Standard time transitions. When changing to DST, there is * * one hour of local time that does not exist, since the clock moves * * forward one hour. Similarly, when changing to standard time, there * * is one hour of local times that occur twice since the clock moves * * back one hour. * * * * This function does not test whether it is passed an erroneous time * * value during the Local -> DST transition that does not exist. * * If passed such a time, an incorrect UTC time value will be returned. * * * * If passed a local time value during the DST -> Local transition * * that occurs twice, it will be treated as the earlier time, i.e. * * the time that occurs before the transistion. * * * * Calling this function with local times during a transition interval * * should be avoided! * *----------------------------------------------------------------------*/time_t Timezone::toUTC(time_t local){ //recalculate the time change points if needed if (year(local) != year(_dstLoc)) calcTimeChanges(year(local)); if (locIsDST(local)) return local - _dst.offset * SECS_PER_MIN; else return local - _std.offset * SECS_PER_MIN;}
开发者ID:benny0924,项目名称:Timezone,代码行数:35,
示例11: utcIsDST/*----------------------------------------------------------------------* * Determine whether the given UTC time_t is within the DST interval * * or the Standard time interval. * *----------------------------------------------------------------------*/boolean Timezone::utcIsDST(time_t utc){ //recalculate the time change points if needed if (year(utc) != year(_dstUTC)) calcTimeChanges(year(utc)); if (_stdUTC > _dstUTC) //northern hemisphere return (utc >= _dstUTC && utc < _stdUTC); else //southern hemisphere return !(utc >= _stdUTC && utc < _dstUTC);}
开发者ID:benny0924,项目名称:Timezone,代码行数:14,
示例12: sepvoid ContentStructuredDocument::parseDate(const string& dateStr, QDate& dateBegin, QDate& dateEnd){ dateBegin=QDate(); dateEnd=QDate(); char sep('/'); //uint64_t firstSep,secondSep; portage 32 64 std::string::size_type firstSep,secondSep; try { if ( (firstSep=dateStr.find(sep)) != string::npos ) { if ( (secondSep=dateStr.find(sep,firstSep+1)) != string::npos ) { // suppose day/month/year // from_uk_string only defined in recent versions of boost// dateBegin=boost::gregorian::from_uk_string(dateStr);// dateEnd=boost::gregorian::from_uk_string(dateStr); // current version knows only year/month/day string day(dateStr,0,firstSep); string month(dateStr,firstSep+1,secondSep-firstSep); string year(dateStr,secondSep+1); string newDateStr=year+'/'+month+'/'+day; dateBegin=QDate::fromString(newDateStr.c_str()); dateEnd=QDate::fromString(newDateStr.c_str()); } else { // one separator : suppose month/year // find end of month string month(dateStr,0,firstSep); string year(dateStr,firstSep+1); unsigned short monthNum=atoi(month.c_str()); unsigned short yearNum=atoi(year.c_str()); dateBegin=QDate(yearNum,monthNum,1); dateEnd=dateBegin.addMonths(1).addDays(-1); } } else if (! dateStr.empty()) { // no separator : suppose year unsigned short yearNum=atoi(dateStr.c_str()); dateBegin=QDate(yearNum,01,01); dateEnd=QDate(yearNum,12,31); } } //catch (boost::bad_lexical_cast& e) { catch (std::exception& e) { DRLOGINIT; LWARN << "Warning: " << e.what(); LWARN << "Failed parsing of date [" << dateStr << "]"; // do nothing, keep not_a_date_time as default value }}
开发者ID:aymara,项目名称:lima,代码行数:54,
示例13: asShortStringQString PartialDate::range(const PartialDate& d) const{ if (year() != d.year()) return asShortString() + "-" + d.asShortString(); QString result = numberToString(year()); if (month() != d.month()) return QString("%1.%2-%3").arg(year()).arg(asShortString(Month | Day)) .arg(d.asShortString(Month | Day)); else if (day() != d.day()) return QString("%1.%2.%3-%4").arg(year()).arg(month()) .arg(asShortString(Day)).arg(d.asShortString(Day)); else return asShortString();}
开发者ID:niklasf,项目名称:chessx,代码行数:13,
示例14: monthDatetime Datetime::preMonth() const { Datetime result; if (*this == Null<Datetime>()) return result; try { int m = month(); result = (m == 1) ? Datetime(year()-1, 12, 1) : Datetime(year(), m-1, 1); } catch(...) { result = Datetime::min(); } return result;}
开发者ID:fasiondog,项目名称:hikyuu,代码行数:13,
示例15: startOfHalfyearDatetime Datetime::preHalfyear() const { Datetime result; if (*this == Null<Datetime>()) return result; try { int m = startOfHalfyear().month(); result = (m <= 6) ? Datetime(year()-1, 7, 1) : Datetime(year(), 1, 1); } catch(...) { result = Datetime::min(); } return result;}
开发者ID:fasiondog,项目名称:hikyuu,代码行数:14,
示例16: startOfQuarterDatetime Datetime::preQuarter() const { Datetime result; if (*this == Null<Datetime>()) return result; try { int m = startOfQuarter().month(); result = (m == 1) ? Datetime(year()-1, 10, 1) : Datetime(year(), m-3, 1); } catch(...) { result = Datetime::min(); } return result;}
开发者ID:fasiondog,项目名称:hikyuu,代码行数:14,
|