Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Creating TimeStamp

Creating TimeStamp

Scheduled Pinned Locked Moved C / C++ / MFC
comtoolshelpquestion
7 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    Programm3r
    wrote on last edited by
    #1

    Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following: char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
    But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards


    The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

    K H D 3 Replies Last reply
    0
    • P Programm3r

      Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following: char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
      But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards


      The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

      K Offline
      K Offline
      kvrnkiran
      wrote on last edited by
      #2

      Hi, For the year, you need to add 1900 (see MSDN for more information). So, your sprintf turn to: sprintf(dateString,"**%4d%02d%02d**",newtime->tm_year **+ 1900** , newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"**%02d%02d%02d**",newtime->tm_hour, newtime->tm_min, newtime->tm_sec); The bold letters are those places where I made changes. Hope that helps. Kiran.

      P 1 Reply Last reply
      0
      • P Programm3r

        Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following: char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
        But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards


        The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

        H Offline
        H Offline
        Hans Ruck
        wrote on last edited by
        #3

        Programm3r wrote:

        format: yyyymmddhhmmss

        Use: _tcsftime (dateString, 20, _T("%Y%m%d%H%M%S"), newtime);


        rechi

        P 1 Reply Last reply
        0
        • H Hans Ruck

          Programm3r wrote:

          format: yyyymmddhhmmss

          Use: _tcsftime (dateString, 20, _T("%Y%m%d%H%M%S"), newtime);


          rechi

          P Offline
          P Offline
          Programm3r
          wrote on last edited by
          #4

          Thank you very much for the help. Regards,


          The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

          1 Reply Last reply
          0
          • K kvrnkiran

            Hi, For the year, you need to add 1900 (see MSDN for more information). So, your sprintf turn to: sprintf(dateString,"**%4d%02d%02d**",newtime->tm_year **+ 1900** , newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"**%02d%02d%02d**",newtime->tm_hour, newtime->tm_min, newtime->tm_sec); The bold letters are those places where I made changes. Hope that helps. Kiran.

            P Offline
            P Offline
            Programm3r
            wrote on last edited by
            #5

            Thanks kvrnkiran for the help :) Regards,


            The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

            1 Reply Last reply
            0
            • P Programm3r

              Hi all, I'm trying to create a time stamp [format: yyyymmddhhmmss], but as always I'm experiencing some problems. I have tried the following: char dateString [20]; char timeString [20]; struct tm *newtime; time_t long_time; time( &long_time ); newtime = localtime( &long_time ); sprintf(dateString,"%d%d%d",newtime->tm_year, newtime->tm_mon, newtime->tm_mday); sprintf(timeString,"%d%d%d",newtime->tm_hour, newtime->tm_min, newtime->tm_sec);
              But I not very familiar with the expression to use. Can anyone please help?? Many Thanks Regards


              The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

              D Offline
              D Offline
              David Crow
              wrote on last edited by
              #6

              Programm3r wrote:

              ...I'm experiencing some problems.

              One of which seems to be not explaining the problem.


              "A good athlete is the result of a good and worthy opponent." - David Crow

              "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

              P 1 Reply Last reply
              0
              • D David Crow

                Programm3r wrote:

                ...I'm experiencing some problems.

                One of which seems to be not explaining the problem.


                "A good athlete is the result of a good and worthy opponent." - David Crow

                "To have a respect for ourselves guides our morals; to have deference for others governs our manners." - Laurence Sterne

                P Offline
                P Offline
                Programm3r
                wrote on last edited by
                #7

                DavidCrow wrote:

                One of which seems to be not explaining the problem.

                Strange that the other two people understood the question :eek: ....


                The only programmers that are better than C programmers are those who code in 1's and 0's..... :) :)Programm3r My Blog: ^_^

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups