LinuxQuestions.org
Review your favorite Linux distribution.
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 02-24-2004, 10:00 AM   #1
Error1312
Member
 
Registered: Feb 2004
Location: Belgium
Distribution: Ubuntu 10.04 Lucid Lynx
Posts: 140

Rep: Reputation: 15
getting the time in C/C++ in a terminal application


Hello everybody.

I want to make a program that gets the system time in hours, minutes and seconds. Than I want to compare the time with the input from the user.

Could somebody give me an example of how to: - get the system time and print it on the screen
- compare two 'times'


Thanks in advance.
 
Old 02-24-2004, 10:16 AM   #2
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
The function gettimeofday from sys/time.h will tell you what you need as far as what time the system thinks it is. I recommend reading the man page on it. There will need to be conversions done on the users input to both display it as H:M:S and to compare them.
 
Old 02-24-2004, 10:45 AM   #3
Error1312
Member
 
Registered: Feb 2004
Location: Belgium
Distribution: Ubuntu 10.04 Lucid Lynx
Posts: 140

Original Poster
Rep: Reputation: 15
Thanks for the answer. I've managed to use the function, but I can't find a way to put it in H:M:S on the screen. Any help would be very appreciated.
 
Old 02-24-2004, 10:58 AM   #4
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 66
Actually, now that I think of it, don't use gettimeofday.

Use time and mktime. Read the man pages for these two functions. Time returns the time in seconds since the Epoch. mktime converts it to a struct with all the information you want. Then you just print out all the information individually.
 
  


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
Run application from terminal with & yumener Linux - Software 1 10-31-2005 01:33 PM
Need a time card application rsmccain General 0 10-26-2005 10:52 AM
Sound only works with one application at a time cspos Linux - General 3 06-14-2005 03:06 AM
enable separate terminal for application i/o in KDevelop mrosati Linux - Software 0 04-21-2004 09:56 AM
Unable to configure terminal application in a Sharp Zaurus PDA [NoR]Archangel Linux - Laptop and Netbook 1 01-27-2004 12:46 PM


All times are GMT -5. The time now is 06:12 PM.

Main Menu
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