ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
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.
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.
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.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.