日期判断常用函数

std::string InnerConfig::GetUTCStringFromTimeT( int32 time )//Fri, 19 Jul 2013 02:09:39 GMT
{
    std::string domain_long_polling;

	base::Time local_time = base::Time::FromTimeT(time);
	base::Time::Exploded server_exploded;
	local_time.UTCExplode(&server_exploded);
	std::string week[7] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
	std::string month[12] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};

#if defined(OS_MACOSX)
    server_exploded.day_of_week = GetWeekdayByYMD(server_exploded.year, server_exploded.month, server_exploded.day_of_month);
#endif
    
	char c_DateTime[128];
	base::snprintf(c_DateTime, 128, "%s, %d %s %d %02d:%02d:%02d GMT", week[server_exploded.day_of_week].c_str(), server_exploded.day_of_month,
		month[server_exploded.month - 1].c_str(), server_exploded.year, server_exploded.hour, server_exploded.minute, server_exploded.second);
	domain_long_polling.append(c_DateTime);

	return domain_long_polling;
}


 

int InnerConfig::GetWeekdayByYMD(const int year, const int month, const int day)
{
    int a = (14 - month) / 12;
    int y = year - a;
    int m = month + 12 * a - 2;
    int d = (day + y + y / 4 - y / 100 + y / 400 + 31 * m / 12) % 7;
    
    return d;
}


 

int InnerConfig::CompareUTCString( const std::string& utc_src, const std::string& utc_dst )//Fri, 19 Jul 2013 02:09:39 GMT
{
	base::Time time_src;
	base::Time time_dst;

	if (!base::Time::FromString(base::SysUTF8ToWide(utc_src).c_str(), &time_src) || !base::Time::FromString(base::SysUTF8ToWide(utc_dst).c_str(), &time_dst))
	{
		return 0;
	}
	
	int64 int_src = time_src.ToInternalValue();
	int64 int_dst = time_dst.ToInternalValue();
	if (int_src < int_dst)
		return -1;
	else if (int_src == int_dst)
		return 0;
	else
		return 1;
}


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值