Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/performance/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
生成cookie过期日期字符串(c+;+;)时的性能问题 我有一个C++代码,它为cookie建立了一个到期日期字符串(类似:”TUU,31-DEC-2037 22:00 GMT“ >,我需要它从现在起为90。这是我的代码: ptime toDay(second_clock::universal_time()); toDay += days(90); date d = toDay.date(); string dayOfWeek = d.day_of_week().as_short_string(); int dayOfMonth = d.day(); string month = d.month().as_short_string(); int year = (int)toDay.date().year(); stringstream strs; strs << dayOfWeek << ", " << std::setfill('0') << std::setw(2) << dayOfMonth << "-" << month << "-" << year << " " << toDay.time_of_day() << " GMT"; string defaultExpiration = strs.str(); 今天的时间(第二个时钟::通用时间()); 今天+=天(90); 日期d=今天。日期(); string dayOfWeek=d.day_of_week().作为_short_string(); int dayOfMonth=d.day(); string month=d.month().as_short_string(); int year=(int)今日.date().year(); stringstream STR; 由于您正在使用boost,我认为您应该尝试一下它的日期时间输入/输出系统。它所做的是在指定的布局中自动设置日期和时间的格式。您可以在上面看到boost教程_C++_Performance_Cookies_String Formatting - Fatal编程技术网

生成cookie过期日期字符串(c+;+;)时的性能问题 我有一个C++代码,它为cookie建立了一个到期日期字符串(类似:”TUU,31-DEC-2037 22:00 GMT“ >,我需要它从现在起为90。这是我的代码: ptime toDay(second_clock::universal_time()); toDay += days(90); date d = toDay.date(); string dayOfWeek = d.day_of_week().as_short_string(); int dayOfMonth = d.day(); string month = d.month().as_short_string(); int year = (int)toDay.date().year(); stringstream strs; strs << dayOfWeek << ", " << std::setfill('0') << std::setw(2) << dayOfMonth << "-" << month << "-" << year << " " << toDay.time_of_day() << " GMT"; string defaultExpiration = strs.str(); 今天的时间(第二个时钟::通用时间()); 今天+=天(90); 日期d=今天。日期(); string dayOfWeek=d.day_of_week().作为_short_string(); int dayOfMonth=d.day(); string month=d.month().as_short_string(); int year=(int)今日.date().year(); stringstream STR; 由于您正在使用boost,我认为您应该尝试一下它的日期时间输入/输出系统。它所做的是在指定的布局中自动设置日期和时间的格式。您可以在上面看到boost教程

生成cookie过期日期字符串(c+;+;)时的性能问题 我有一个C++代码,它为cookie建立了一个到期日期字符串(类似:”TUU,31-DEC-2037 22:00 GMT“ >,我需要它从现在起为90。这是我的代码: ptime toDay(second_clock::universal_time()); toDay += days(90); date d = toDay.date(); string dayOfWeek = d.day_of_week().as_short_string(); int dayOfMonth = d.day(); string month = d.month().as_short_string(); int year = (int)toDay.date().year(); stringstream strs; strs << dayOfWeek << ", " << std::setfill('0') << std::setw(2) << dayOfMonth << "-" << month << "-" << year << " " << toDay.time_of_day() << " GMT"; string defaultExpiration = strs.str(); 今天的时间(第二个时钟::通用时间()); 今天+=天(90); 日期d=今天。日期(); string dayOfWeek=d.day_of_week().作为_short_string(); int dayOfMonth=d.day(); string month=d.month().as_short_string(); int year=(int)今日.date().year(); stringstream STR; 由于您正在使用boost,我认为您应该尝试一下它的日期时间输入/输出系统。它所做的是在指定的布局中自动设置日期和时间的格式。您可以在上面看到boost教程,c++,performance,cookies,string-formatting,C++,Performance,Cookies,String Formatting,基本上,您需要以您想要的格式为时间输出设置一个boost方面——有很多,我相信您会找到答案的 我不确定这是否会带来性能改进,但我相信值得一试。毕竟,这就是该子系统的目的——输出日期和时间。找到了一种非常快速的方法来使用,现在看起来是这样的: ptime today(second_clock::universal_time()); today += days(90); date d = today.date(); int dayOfMonth = d.day(); int hoursOfDay =

基本上,您需要以您想要的格式为时间输出设置一个boost方面——有很多,我相信您会找到答案的


我不确定这是否会带来性能改进,但我相信值得一试。毕竟,这就是该子系统的目的——输出日期和时间。

找到了一种非常快速的方法来使用,现在看起来是这样的:

ptime today(second_clock::universal_time());
today += days(90);
date d = today.date();
int dayOfMonth = d.day();
int hoursOfDay = today.time_of_day().hours();
int minutesOfDay = today.time_of_day().minutes();

//this function if from "FastFormat"
string defaultExpiration(StringFormatter::Format("{0}, {1}{2}-{3}-{4} {5}{6}:{7}{8}:00 GMT",
    d.day_of_week().as_short_string(),
    dayOfMonth < 10 ? "0" : "",
    dayOfMonth,
    d.month().as_short_string(),
    (int)d.year(),
    hoursOfDay < 10 ? "0" : "",
    hoursOfDay,
    minutesOfDay < 10 ? "0" : "",
    minutesOfDay
    ));
今天的时间(第二个时钟::通用时间()); 今天+=天(90); 日期d=今天。日期(); int dayOfMonth=d.day(); int hoursOfDay=今天。一天中的时间()小时(); int minutesOfDay=今天。一天中的时间()分钟(); //如果来自“FastFormat”,则此函数 字符串defaultExpiration(StringFormatter::Format(“{0},{1}{2}-{3}-{4}{5}{6}:{7}{8}:00 GMT”, d、 周的第天()。如字符串()所示, 月日<10?“0”:“, 月日, d、 月份()。作为\u短字符串(), (int)d.年份(), 日小时数<10?“0”:“, 一天的几个小时, 日分钟数<10?“0”:“, 一天的分钟数 ));
我不知道日期和时间类使用的是什么库,但它是否有类似的功能?或者你可以得到一个
struct tm
并自己使用
strftime
?@JoachimPileborg:I use
boost::posix_time
。我看了一下,但是找不到类似的东西。然后你有了
to_tm
函数,你可以用它来获得一个
struct tm
,你可以在
strftime
中使用它。谢谢,这确实是一个很好的开始。我将更新性能是否得到改善。):这没有多大帮助。“格式化”功能和io支持都使用流媒体。对不起,我希望这会有所帮助。