LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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-27-2005, 02:57 PM   #1
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
Time


I was trying to put together a program recently that would create a txt log file each time a user created a log entry it would time stamp the entry.


Now my question is is there an eazier way to get the current time so you can put it into a string other then using the time.h file or if you do what would be the correct way to obtain the time in this kinda format --> 8:45pm or possibly military time.



I know this can be diffrent on difrent operating systems so im trying to keep as general as poosilble with the answers.
 
Old 02-27-2005, 04:27 PM   #2
tsphan
Member
 
Registered: Jan 2005
Location: Clackamas, Oregon, US
Distribution: Slackware 10.2
Posts: 154

Rep: Reputation: 30
did you try the "date" command?

if you want it 8:45pm, it's [date "+%I:%M%P"], everything in the brackets.

if you want it 8:45PM, it uses a lowercase %p, date --help should show you.
 
Old 02-27-2005, 04:35 PM   #3
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Original Poster
Rep: Reputation: 87
Sorry mabye i should have clarifyed this is for C: programming not bash


I could however use the date command in the program but was really looking for something more in a .h file or something. Mabye i should take a look at date's source file.
 
Old 02-27-2005, 05:26 PM   #4
skoona
Member
 
Registered: Mar 2004
Location: Indiana, USA
Distribution: Fedora, CentOS, Ubuntu, OS/X, Raspbian
Posts: 90

Rep: Reputation: 18
Why did you not want to use time.h ?

I would offer time(), and ctime_r() - where ctime_r produces a string like this "Wed Jun 30 21:49:08 1993\n" - notice it includes a newline char at the end.

For portability the GLib library also has a collection of time and date functions that are portable across most nix systems and windoz.

Last edited by skoona; 02-27-2005 at 05:27 PM.
 
  


Reply



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
Doub about `net time set` and daylight saving time Thakowbbery Linux - Software 0 10-17-2005 05:23 AM
ps2 mouse freezing on FC1/FC2 from time to time farpoint Linux - Hardware 5 08-14-2005 02:20 PM
How to syncronize my system time by public time server? hakansun Linux - Networking 1 09-10-2004 05:10 AM
no signal when starting xorg for the 1st time (but the second time works fine) bungalowbill Linux - Software 0 06-04-2004 09:56 AM
Setting System Time: kernel in wrong time zone warrenweiss Linux - General 7 05-15-2004 03:25 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:02 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
Open Source Consulting | Domain Registration