ctime library

This is a discussion on ctime library within the C++ Programming forums, part of the General Programming Boards category; hi im trying to read the current time of the computer , but all what i was able to get ...

  1. #1
    Registered User
    Join Date
    Feb 2005
    Posts
    11

    ctime library

    hi
    im trying to read the current time of the computer , but all what i was able to get is the day , month, and year but not the name of the day ( sunday , monday .... ) , im just wondering is there any function in the ctime library that might give me the day name ?
    thanks

  2. #2
    Senior Member joshdick's Avatar
    Join Date
    Nov 2002
    Location
    Phildelphia, PA
    Posts
    1,146
    Last edited by joshdick; 04-13-2005 at 02:37 PM.

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    >im just wondering is there any function in the ctime library that might give me the day name ?
    You could use strftime() to format the time.
    Code:
    #include <ctime>
    #include <iostream>
    using namespace std;
    
    int main()
    {
       time_t now = time(NULL);
       tm *t = localtime(&now);
       char day_of_week[30];
       strftime(s, sizeof(day_of_week), "%A", t);
       cout << "Today is " << day_of_week << endl;
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. What's an import library?
    By chiefmonkey in forum C++ Programming
    Replies: 1
    Last Post: 06-19-2009, 06:00 PM
  2. Property Set Library (PSL) - Announcement
    By vultur_gryphus in forum Projects and Job Recruitment
    Replies: 0
    Last Post: 05-29-2008, 07:04 AM
  3. Makefile for a library
    By sirmoreno in forum Linux Programming
    Replies: 5
    Last Post: 06-04-2006, 05:52 AM
  4. very weird .h problem
    By royuco77 in forum C++ Programming
    Replies: 1
    Last Post: 09-11-2005, 08:55 AM
  5. better c string functions
    By samps005 in forum C Programming
    Replies: 8
    Last Post: 11-04-2003, 01:28 PM

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