time_t doing not what i expect

This is a discussion on time_t doing not what i expect within the C++ Programming forums, part of the General Programming Boards category; what im trying to do is store the time & date into a string.. Code: string timeformat; time_t x; tm ...

  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    91

    time_t doing not what i expect

    what im trying to do is store the time & date into a string..


    Code:
    string timeformat;
    time_t x;
    tm * time_;
    time(&x); // get current time_t value
    time_ = localtime(&x);
    cout << time_->tm_mday << endl;    //here it prints out the right thing..
    
    timeformat = time_->tm_mday;  
    // here it doesnt do what i want it to do. here timeformat = "";
    ??
    Last edited by paperbox005; 08-15-2004 at 12:55 AM.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    Use strftime() to format time as a string
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User
    Join Date
    Jul 2004
    Posts
    91
    that function returns a size_t ??
    whats that ?
    Code:
    function prototype
    
    size_t strftime(char *s, size_t max, const char *format, const struct tm *tm);
    hrm how do you actually use this function
    Last edited by paperbox005; 08-15-2004 at 01:24 AM.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,531
    I thought actually reading the manual would be a start

    Code:
    char formattedtime[100];
    strftime( formattedtime, sizeof formattedtime, "%H:%M:%S", time_ );
    // now put it in a C++ string
    timeformat = formattedtime;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Hardware Engineer
    Join Date
    Sep 2001
    Posts
    1,398

    size_t

    that function returns a size_t ??
    whats that ?
    size_t is essentially an unsigned integer. It's defined in <cstddef>.

    This is from the C-language standard (note the old-style dot-h header):
    7.17 Common definitions <stddef.h>
    1 The following types and macros are defined in the standard header <stddef.h>....

    size_t
    which is the unsigned integer type of the result of the sizeof operator...
    This is from dinkumware.com:
    size_t

    typedef ui-type size_t;

    The type is the unsigned integer type ui-type of an object that you declare to store the result of the sizeof operator.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What to expect from pre-calc?
    By psychopath in forum A Brief History of Cprogramming.com
    Replies: 31
    Last Post: 06-26-2007, 05:34 PM
  2. using expect script in C program
    By nitinmhetre in forum Linux Programming
    Replies: 1
    Last Post: 12-21-2006, 07:25 AM
  3. if clause not working as I expect.
    By luise.valencia in forum C Programming
    Replies: 4
    Last Post: 04-16-2005, 08:35 PM
  4. C++ calling an expect module
    By 15332000 in forum C++ Programming
    Replies: 0
    Last Post: 09-03-2004, 01:00 PM
  5. What to expect for pay rate developing software
    By Shadow12345 in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 11-04-2002, 01:56 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21