system clock

This is a discussion on system clock within the C++ Programming forums, part of the General Programming Boards category; i am writing a program that i need to check the date, and return it as a value. does anyone ...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    7

    system clock

    i am writing a program that i need to check the date, and return it as a value. does anyone know what i should do to make it read the date? i dont know where i would tell it to look. thanks.

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,541
    Look up some of the functions in time.h
    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
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You may think that the answer to this should be REALLY easy, and I suppose I could make a very easy answer - but I prefer to give you GOOD help rather than EASY FOR ME help.

    Besides getting the current date/time, what do you want to do with it? Just print it, or do some calculations or some such?

    --
    Mats

  4. #4
    Registered User
    Join Date
    Nov 2005
    Posts
    7
    i want to write a program to tell me the date every time i start the comp. i can make it autorun, but i just need to figure out how to make it tell me the date. and ty, i will look up time.h. any more help is appreciated

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    What's wrong with this batch file?

    Code:
    // file: timedate.bat
    date < NUL: >> mytimestamp.txt
    time < NUL: >> mytimestamp.txt
    --
    Mats

  6. #6
    and the hat of sweating
    Join Date
    Aug 2007
    Location
    Toronto, ON
    Posts
    3,545
    I'm not sure what the purpose of the < NUL: is, but a better version (without the Enter new Date prompts) is:

    Code:
    @ECHO OFF
    DATE /T >> C:\SystemStart.txt
    TIME /T >> C:\SystemStart.txt
    You can also check the System Event Log to see when the system starts & stops (i.e. check when the Event Log service starts & stops).

  7. #7
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Quote Originally Posted by cpjust View Post
    I'm not sure what the purpose of the < NUL: is, but a better version (without the Enter new Date prompts) is:

    Code:
    @ECHO OFF
    DATE /T >> C:\SystemStart.txt
    TIME /T >> C:\SystemStart.txt
    You can also check the System Event Log to see when the system starts & stops (i.e. check when the Event Log service starts & stops).
    The < NUL: is there to avoid the "enter new date" prompt - I didn't know that recent versions of Windows support an option to avoid that...

    NUL: is the same as /dev/null in Unix/Linux, that is, a device that just returns end of file when read and "eats" anything written to it without any further processing. So a good place to input nothingness and a good place to get rid of unwanted output.

    --
    Mats

  8. #8
    Registered User
    Join Date
    Jul 2007
    Posts
    16
    how can I check the username of the windows account that logged in?
    So I can make a app of the time/date/username who logged into windows..

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,211
    Quote Originally Posted by thelimpkid View Post
    how can I check the username of the windows account that logged in?
    http://msdn2.microsoft.com/en-us/library/ms724432.aspx

    As per MSDN instructions, include Windows.h, and link with Advapi32.lib.

    Call it with something like this:

    Code:
    #include <Windows.h>
    
    ...
    
    char szUsername[256];
    
    ...
    
    GetUserName(szUsername, sizeof(szUsername));
    
    /* szUsername now contains the current Windows username */

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Logical Error in Clock program
    By SVXX in forum C++ Programming
    Replies: 0
    Last Post: 05-10-2009, 12:12 AM
  2. Outside influences on clock cycles? (clock_t)
    By rsgysel in forum C Programming
    Replies: 4
    Last Post: 01-08-2009, 05:15 PM
  3. Linux database system needed
    By BobS0327 in forum Tech Board
    Replies: 7
    Last Post: 06-11-2006, 03:56 PM
  4. New system build wont boot
    By lightatdawn in forum Tech Board
    Replies: 7
    Last Post: 12-02-2005, 05:58 AM
  5. BIOS system and memory allocation problem
    By beely in forum Tech Board
    Replies: 9
    Last Post: 11-25-2003, 06:12 AM

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