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 6777333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:08:06+00:00 2026-05-26T16:08:06+00:00

I wrote a little structure for getting certain time information. This structure is a

  • 0

I wrote a little structure for getting certain time information. This structure is a helper,
for my logging class im planning to write. Here is the code:

struct UTime
{
  char Month      [4];
  char DayOfMonth [3];
  char DayOfWeek  [4];
  char Year       [5];
  char Time       [9];
  char Full       [25];

  UTime()
  {
    this->refresh();
  }

  void refresh()
  {
    char      TimeBuffer[26] = {};
    time_t    RawTime        = 0;

    time(&RawTime);
    ctime_s(TimeBuffer, 26*sizeof(char), &RawTime);

    this->DayOfWeek[0]  = TimeBuffer[0];
    this->DayOfWeek[1]  = TimeBuffer[1];
    this->DayOfWeek[2]  = TimeBuffer[2];
    this->DayOfWeek[3]  = 0;

    this->Month[0]      = TimeBuffer[4];
    this->Month[1]      = TimeBuffer[5];
    this->Month[2]      = TimeBuffer[6];
    this->Month[3]      = 0;

    this->DayOfMonth[0] = TimeBuffer[8];
    this->DayOfMonth[1] = TimeBuffer[9];
    this->DayOfMonth[2] = 0;

    this->Time[0]       = TimeBuffer[11];
    this->Time[1]       = TimeBuffer[12];
    this->Time[2]       = TimeBuffer[13];
    this->Time[3]       = TimeBuffer[14];
    this->Time[4]       = TimeBuffer[15];
    this->Time[5]       = TimeBuffer[16];
    this->Time[6]       = TimeBuffer[17];
    this->Time[7]       = TimeBuffer[18];
    this->Time[8]       = 0;

    this->Year[0]       = TimeBuffer[20];
    this->Year[1]       = TimeBuffer[21];
    this->Year[2]       = TimeBuffer[22];
    this->Year[3]       = TimeBuffer[23];
    this->Year[4]       = 0;

    memcpy(this->Full, TimeBuffer, 25);
    this->Full[24] = 0;
  }
}; // struct UTime;

Now Id like to add a function wich returns a formatted version of the time information.
For example:

std::string formatted = utime.get(Year, Month)

This function should return something like: “2011 Nov”, or another example:

std::string formated = utime.get(DayOfWeek, Time);

This function should return something like: “Mon 20:43:24”. Can anyone please point me in the most effecient way to do this? Im just not sure about effeciency because in a logger this function might get called alot. Thank you very much.

  • 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-05-26T16:08:07+00:00Added an answer on May 26, 2026 at 4:08 pm

    You can use strftime. It supports lots of format

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Some time ago I wrote a little piece of code to ask about on
i wrote a little addin, which does some formatting of my C# code. in
I wrote little WPF application with 2 threads - main thread is GUI thread
I wrote a little daemon in Perl that calls up FFMpeg to encode a
i wrote a little test programm which queries the status servlet of a tomcat
I wrote a little search script for a client, it works and words get
I wrote a little monkeypatch to the Rails MySQLAdapter and want to package it
I wrote a little program that solves 49151 sudoku's within an hour for an
I wrote a little Haskell program to find the area of a triangle, primarily
I've been playing with Python for a while and wrote a little program to

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.