Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Display System Time

GeorgeSGeorgeS Member Posts: 13
How do you display the system time? Is there a function, e.g. time.h?
I'm using RedHat Linux and writing code in C. I need to constantly display 9using a loop) the system time and maybe date in a standard format.

Thanks,
George

Comments

  • Geeth AsokanGeeth Asokan Member Posts: 127
    Hi,

    As far as I know there are functions [b]time()[/b] and [b]ctime()[/b] in C/C++.

    Here are some examples of how to use them.

    [code]
    //Program uses ctime to convert a time_t variable into a human readable
    //string in form Fri Jan 28 00:00:00 2000



    #include
  • GeorgeSGeorgeS Member Posts: 13
    Thank you very much. Immediately after I posted my message I found time.h and a very good Unix site which provided useful examples also.
    Again, I appreciate your help.
  • azidstarazidstar Member Posts: 10
    : Thank you very much. Immediately after I posted my message I found time.h and a very good Unix site which provided useful examples also.
    : Again, I appreciate your help.
    :
    Heres another example. Maybe a little bit overkill, but ...

    use the system(); func to call time in the system.
    Now the problem with system is that it just returns a value if succeded or not. So you have to pipe the output to a textfile and read it.

    system("time > dateTextFile");

    I know this is a very complicated way to solve the problem, but maybe you will have some use of the system command some other time ;-)
    Is there someone out there who has a good way of catching the output of system() ???




  • Shawn CarterShawn Carter Member Posts: 0

    ________ | http://forcoder.org | free video tutorials and ebooks about | Perl MATLAB Assembly Swift Go C# Python C Visual Basic Java Ruby R Objective-C JavaScript Visual Basic .NET Delphi PHP PL/SQL C++ Scratch Julia Lisp Bash Alice Logo Kotlin Erlang Hack Scheme Prolog Fortran FoxPro VBScript Ada Dart Apex Lua Transact-SQL ABAP ML D F# Awk SAS Rust COBOL Scala Crystal LabVIEW Clojure | _______

Sign In or Register to comment.