当前位置: 首页>>代码示例>>C++>>正文


C++ TimeDuration::getSeconds方法代码示例

本文整理汇总了C++中TimeDuration::getSeconds方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeDuration::getSeconds方法的具体用法?C++ TimeDuration::getSeconds怎么用?C++ TimeDuration::getSeconds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeDuration的用法示例。


在下文中一共展示了TimeDuration::getSeconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: formatDate

String LanguageCulture::formatDate(const DateTime &dt, const DateTime::DateTimePattern &pattern, int32 timeOffset, int32 timeDST) const
{
	// I pattern restituiti dal .net non contengono mai i nomi dei mesi abbreviati... a parte l' RFC, non usato qui...
	// per usarli dovremmo creare 3 nuovi pattern 'm_medium'... ne vale la pena?
	
	if(pattern == DateTime::dpUserFriendly)
	{
		DateTime now = DateTime::now();
		if(dt > now)
		{
			return formatDate(dt, m_longDatePattern + _S(" ") + m_longTimePattern, timeOffset, timeDST);
		}

		TimeDuration delta = now - dt;

		uint32 days = delta.getHours()/24;

		if(days > 4)
			return formatDate(dt, m_longDatePattern + _S(" ") + m_longTimePattern, timeOffset, timeDST);

		if(days > 1)
			return conversions::to_utf16(days) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.days_ago"));

		if(days == 1)
			return LanguageManager::instance()->getText(getID(),_S("datetime.yesterday_at")) + _S(" ") + formatDate(dt, m_longTimePattern, timeOffset, timeDST);

		if(delta.getHours() > 1)
			return conversions::to_utf16(delta.getHours()) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.hours_ago"));

		if(delta.getHours() == 1)
			return conversions::to_utf16(delta.getHours()) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.hour_ago"));
		
		if(delta.getMinutes() > 1)
			return conversions::to_utf16(delta.getMinutes()) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.minutes_ago"));

		if(delta.getMinutes() == 1)
			return conversions::to_utf16(delta.getMinutes()) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.minute_ago"));

		if(delta.getSeconds() > 5)
			return conversions::to_utf16(delta.getSeconds()) + _S(" ") + LanguageManager::instance()->getText(getID(),_S("datetime.seconds_ago"));

		return LanguageManager::instance()->getText(getID(),_S("datetime.now_ago"));
	}
	else
	{
		String sPattern;

		switch(pattern)
		{
		case DateTime::dpLongDatePattern:		sPattern = m_longDatePattern;
												break;

		case DateTime::dpShortDatePattern:		sPattern = m_shortDatePattern;
												break;

		case DateTime::dpLongTimePattern:		sPattern = m_longTimePattern;
												break;

		case DateTime::dpShortTimePattern:		sPattern = m_shortTimePattern;
												break;

		case DateTime::dpLongDateTimePattern:	sPattern = m_longDatePattern + _S(" ") + m_longTimePattern;
												break;

		case DateTime::dpShortDateTimePattern:	sPattern = m_shortDatePattern + _S(" ") + m_shortTimePattern;
												break;

		case DateTime::dpUserFriendly:			sPattern = m_shortDatePattern + _S(" ") + m_shortTimePattern;
												break;

		case DateTime::dpRFC822:				
			{
				// Copiata da HttpParser::toString
				static const char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
				static const char *days[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };

				DateTime::posix_time time = dt.toPosixTime();

				OS_ASSERT(time.date().day_of_week() < OS_COUNTOF(days));
				OS_ASSERT(static_cast<uint32>(time.date().month() - 1) < OS_COUNTOF(months));

				return (boost::format("%s, %02d %s %04d %02d:%02d:%02d GMT") % days[time.date().day_of_week()] % time.date().day() % months[time.date().month() - 1] % time.date().year() % time.time_of_day().hours() % time.time_of_day().minutes() % time.time_of_day().seconds()).str();

			} break;
		}

		return formatDate(dt, sPattern, timeOffset, timeDST);
	}
}
开发者ID:,项目名称:,代码行数:89,代码来源:


注:本文中的TimeDuration::getSeconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。