I have a c++ code which build an expiration date string for cookie (something like: "Thu, 31-Dec-2037 22:00:00 GMT") I need it to be 90 from “now”. This is my code:
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();
The performance of this code is really bad, I would guess it’s the stringstream use.
If any of you have an alternative which should be faster, I would be happy to test it.
Thanks !
Found a sagnificant faster way to do it using FastFormat, and now it looks like that: