LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices



Reply
 
Search this Thread
Old 09-08-2002, 07:07 AM   #1
jax79sg
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, 08:40 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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:

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

int main()
{
     time_t t;
     time(&t);
     puts(ctime(&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 08:42 AM.
 
Old 09-08-2002, 12:51 PM   #3
sarin
Member
 
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>
main()
{
system("date");
}
--Sarin
 
Old 09-08-2002, 01:02 PM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
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 01:04 PM.
 
  


Reply


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 03:31 PM
webmin: there are too many zones on your system to display here cccc Linux - Software 0 10-11-2005 07:10 PM
X display on another system unzari Fedora 2 04-28-2005 02:14 AM
display all users on system jkassemi Linux - Newbie 2 02-19-2005 12:12 PM
system info display application? chunlee Linux - Software 1 12-20-2004 11:52 PM


All times are GMT -5. The time now is 03:43 PM.

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