Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8483243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:02:37+00:00 2026-06-10T20:02:37+00:00

I have a c++ code which build an expiration date string for cookie (something

  • 0

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 !

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:02:39+00:00Added an answer on June 10, 2026 at 8:02 pm

    Found a sagnificant faster way to do it using FastFormat, and now it looks like that:

    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
        ));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have code which needs to do something like this There is a list
I have code which I would like to enable for compilation when I build
I have some code which builds an array of date ranges. I then call
I have code which looks like: private static DirectiveNode CreateInstance(Type nodeType, DirectiveInfo info) {
I have a powershell build script which checks out code and increments a build
I have a code base which compiles fine in all other NEON compilers, ndk-build,
I have the following code which splits a string of numbers (separated by a
I have downloaded SSHCore source code which uses libssh2 library. That code build successfully,
I have the code below which is intended to build a dictionary object with
On a small embedded system project we have some code which we would like

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.