简体   繁体   中英

Embedding Unix date in a C program

I have a C program running on a Unix box.

I would like to print a timestamp to an output file - at the moment I use the command date to print the datetime on the terminal.

fprintf(outputfile, "%s ", date);

How do I go about doing this?

Use POSIX strftime(3) - format date and time for a C solution. It use the same format strings as date(1)

I also recommend you read the standard library intro(3) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM