Latest LQ Deal: Complete CCNA, CCNP & Red Hat Certification Training Bundle
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 09-08-2002, 06:07 AM   #1
LQ Newbie
Registered: Aug 2002
Location: Singapore
Distribution: Redhat 7.3
Posts: 13

Rep: Reputation: 0
display system

How do i display the system time? using c language.
time doesnt help/
Old 09-08-2002, 07:40 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
time() does help actually, but is does only part of the job.
It writes the number of seconds passed since midnight UTC (GMT) on 1 january 1970 in a variable of the type "time_t". So you need some way to convert that number to a readable string and print it on stdout.

Here's an example of the, more or less, easiest way to prints the local (i.e. not UTC/GMT) system time formatted as a human readable string:

#include <time.h>
#include <stdio.h>

int main()
     time_t t;
     return 0;
Some man pages to read about the other options to format a time-string:

man 2 time
man 3 ctime
man 3 strftime

Last edited by Hko; 09-08-2002 at 07:42 AM.
Old 09-08-2002, 11:51 AM   #3
Registered: May 2001
Location: India, Kerala, Thrissur
Distribution: FC 7-10
Posts: 354
Blog Entries: 2

Rep: Reputation: 34
the simplest I can think of is
#include <stdio.h>
Old 09-08-2002, 12:02 PM   #4
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 110Reputation: 110
I guess it is the simplest, but it looks a little like "cheating" to me, because there is another process created in which an external program is started. It 's also not very efficient in terms of resources.

Last edited by Hko; 09-08-2002 at 12:04 PM.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
system-config-display-tui BeauSanders Linux - Hardware 14 06-03-2008 02:31 PM
webmin: there are too many zones on your system to display here cccc Linux - Software 0 10-11-2005 06:10 PM
X display on another system unzari Fedora 2 04-28-2005 01:14 AM
display all users on system jkassemi Linux - Newbie 2 02-19-2005 11:12 AM
system info display application? chunlee Linux - Software 1 12-20-2004 10:52 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration