time_t

Discussion in 'C++' started by magix, Sep 29, 2006.

  1. magix

    magix Guest

    I saw below code:

    std::time_t now;
    std::time ( &now );
    std::stringstream stream;
    stream << "output_" << asctime(localtime( &now )) << ".txt" <<
    std::flush;

    How to convert asctime(localtime( &now )) to be timestamp format like
    20060930130102 ?

    Thanks & Regards.
    magix, Sep 29, 2006
    #1
    1. Advertising

  2. magix

    Phlip Guest

    magix wrote:

    > How to convert asctime(localtime( &now )) to be timestamp format like
    > 20060930130102 ?


    strftime()

    --
    Phlip
    http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
    Phlip, Sep 29, 2006
    #2
    1. Advertising

  3. magix

    Gavin Deane Guest

    magix wrote:
    > I saw below code:
    >
    > std::time_t now;
    > std::time ( &now );
    > std::stringstream stream;
    > stream << "output_" << asctime(localtime( &now )) << ".txt" <<
    > std::flush;
    >
    > How to convert asctime(localtime( &now )) to be timestamp format like
    > 20060930130102 ?


    How about this:

    #include <ctime>
    #include <sstream>
    #include <string>

    int main()
    {
    std::time_t now;
    std::time ( &now );
    std::stringstream stream;
    stream << "output_" << asctime(localtime( &now )) << ".txt" <<
    std::flush;

    std::string s = stream.str();

    // Write code to modify the contents of s to meet your needs.
    }

    If you have trouble writing the the code to modify the contents of s to
    meet your needs, FAQ 5.8 explains how to post a question about code you
    are having trouble with.
    http://www.parashift.com/c -faq-lite/how-to-post.html#faq-5.8
    Follow all those guidelines and you will get the help you need.

    What you will have a lot less luck finding of course is anyone who will
    donate their time and effort to write all your code for you. Depending
    on whether this is your own programming project or something for a
    class or school, asking others to do your work for you without showing
    how you've attempted it yourself and where you got stuck is called
    either laziness or cheating.

    Gavin Deane
    Gavin Deane, Sep 29, 2006
    #3
  4. magix

    magix Guest

    "Phlip" <> wrote in message
    news:Bc9Tg.163$...
    > magix wrote:
    >
    >> How to convert asctime(localtime( &now )) to be timestamp format like
    >> 20060930130102 ?

    >
    > strftime()
    >
    > --
    > Phlip
    > http://www.greencheese.us/ZeekLand <-- NOT a blog!!!
    >
    >


    Thanks. this is exactly what I'm looking for.
    magix, Sep 29, 2006
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TWFyaw==?=

    DateTime to time_t bug

    =?Utf-8?B?TWFyaw==?=, May 17, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    4,661
    Steven Cheng[MSFT]
    May 18, 2004
  2. Anand CS

    converting to time_t

    Anand CS, Jul 3, 2003, in forum: C Programming
    Replies:
    1
    Views:
    7,706
    Luke Driscoll
    Jul 3, 2003
  3. Dave Sinkula

    Casting (time_t)(-1)

    Dave Sinkula, Mar 2, 2004, in forum: C Programming
    Replies:
    4
    Views:
    638
    Dan Pop
    Mar 2, 2004
  4. j0mbolar

    time_t in seconds

    j0mbolar, Apr 18, 2004, in forum: C Programming
    Replies:
    6
    Views:
    10,249
    Dan Pop
    Apr 19, 2004
  5. Tomas Deman

    borland time_t conversion

    Tomas Deman, Jun 7, 2004, in forum: C Programming
    Replies:
    1
    Views:
    1,074
    Richard Bos
    Jun 7, 2004
Loading...

Share This Page