Results 1 to 9 of 9

Thread: Time

  1. #1

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Question Time

    Hello,

    i want to print out the Systemtime:

    m_sTime.Format("%d:%d:%d", curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond());

    That will print out: 3:4:9 for Example.

    But ... I want it looks like: 03:04:09.

    How do I format the String to get the expected Result?

    Any help' s welcome,

    thx

  2. #2
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    m_sTime.Format("%2d:%2d:%2d", curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond());

    should work...
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  3. #3

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Question Blank

    Hello,

    at first thank you for your Reply. If I format the String like you wrote I will get Blanks in my String not the Zero Number. The Result will look as follows: 3: 4: 9

    Have any other Idea?

    Many thanks.

  4. #4
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    Strange! But you can try to get CTime::Format() to work. (Or is it CTimeSpan?)
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  5. #5

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Fill up Spaces

    Hello,

    better using: m_sTime.Format("%02d:%02d:%02d", curTime.GetHour(), curTime.GetMinute(), curTime.GetSecond());

    Thanks for your help,

    Myvar

  6. #6
    Fanatic Member prog_tom's Avatar
    Join Date
    May 2001
    Location
    Los Angeles and Little Rock
    Posts
    810

    Angry time.h

    /*This is the code give you the time
    */

    #include <iostream>
    #include <time.h>
    #include <ctime>
    using namespace std;
    int main(){
    system("cls");

    time_t T;
    time(&T);
    cout<<ctime(&T)<<endl;
    system("pause");
    exit(0);
    }

    prog_tom
    JOIN THE REVOLUTION!!!! Dual T3 backedup science community.
    http://physics.sviesoft.com/forum

  7. #7
    Kitten CornedBee's Avatar
    Join Date
    Aug 2001
    Location
    In a microchip!
    Posts
    11,594
    tom: even easier would be:
    cout << ctime(time(NULL)) << endl;
    All the buzzt
    CornedBee

    "Writing specifications is like writing a novel. Writing code is like writing poetry."
    - Anonymous, published by Raymond Chen

    Don't PM me with your problems, I scan most of the forums daily. If you do PM me, I will not answer your question.

  8. #8

    Thread Starter
    Member Myvar's Avatar
    Join Date
    Sep 2001
    Location
    Deutschland/Germany
    Posts
    34

    Nice

    Nice Code up there.

    I do not write a Console - Application.

    Thx anyway,

    Myvar

  9. #9
    Monday Morning Lunatic parksie's Avatar
    Join Date
    Mar 2000
    Location
    Mashin' on the motorway
    Posts
    8,169
    Code:
    m_sTime = ctime(time(NULL));
    The benefit of doing it this way is that this is GUARANTEED to be a specific format, for example the time is always in the same position in the returned string.
    I refuse to tie my hands behind my back and hear somebody say "Bend Over, Boy, Because You Have It Coming To You".
    -- Linus Torvalds

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width