Thread: formatting a date

  1. #1
    Registered User
    Join Date
    Jun 2002
    Posts
    10

    Question formatting a date

    I am using c++ and is there an method i can use to format a date into the following form 06/07/02 which is the month, day and year??

  2. #2
    Evil Member
    Join Date
    Jan 2002
    Posts
    638
    Well what is the information as you get it?

    Are you using a Date class or just a string. If either, how is the information formatted?

    If its a class, look into the (global) operator<< that is associated with it.

    If its a string, look into string manipulation.

  3. #3
    Registered User
    Join Date
    Jun 2002
    Posts
    10
    i would like to use <ctime> becuase i need the date from the computer is this even possible??

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Here's one way.
    Code:
       time_t time_now;
       char s[9];
    
       time_now = time(NULL);
       strftime(s,sizeof(s),"%m/%d/%y",localtime(&time_now));
       cout << s << endl;

  5. #5
    Registered User
    Join Date
    Jun 2002
    Posts
    10
    Thanks a lot
    it works perfectly

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. dos game help
    By kwm32 in forum Game Programming
    Replies: 7
    Last Post: 03-28-2004, 06:28 PM
  4. Extracting and formatting today's date
    By Chewie in forum C Programming
    Replies: 4
    Last Post: 08-16-2001, 07:45 AM