aboutsummaryrefslogtreecommitdiffstats
path: root/man3/strftime.3
diff options
context:
space:
mode:
authorMichael Kerrisk <mtk.manpages@gmail.com>2005-11-23 09:34:07 +0000
committerMichael Kerrisk <mtk.manpages@gmail.com>2005-11-23 09:34:07 +0000
commit7119b0d1442c308a77384c0053345be0fdd7622e (patch)
tree2965ae3b08d7c607480dc94bb732139a6ac04a32 /man3/strftime.3
parenta4020d9ca42a141d50b790eb78ce7233714019d8 (diff)
downloadman-pages-7119b0d1442c308a77384c0053345be0fdd7622e.tar.gz
Added example program
Diffstat (limited to 'man3/strftime.3')
-rw-r--r--man3/strftime.345
1 files changed, 45 insertions, 0 deletions
diff --git a/man3/strftime.3 b/man3/strftime.3
index e5693d51bf..2b37e00917 100644
--- a/man3/strftime.3
+++ b/man3/strftime.3
@@ -318,6 +318,51 @@ const struct tm *tm) {
.br
}
.RE
+.SH EXAMPLE
+The program below can be used to experiment with
+.BR strftime ().
+.nf
+
+#include <time.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+ char outstr[200];
+ time_t t;
+ struct tm *tmp;
+
+ t = time(NULL);
+ tmp = localtime(&t);
+ if (tmp == NULL) {
+ perror("localtime");
+ exit(EXIT_FAILURE);
+ }
+
+ if (strftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
+ fprintf(stderr, "strftime returned 0");
+ exit(EXIT_FAILURE);
+ }
+
+ printf("Result string is \\"%s\\"\\n", outstr);
+ exit(EXIT_SUCCESS);
+} /* main */
+.fi
+.PP
+Some examples of the result string produced by the glibc implementation of
+.BR strftime ()
+are as follows:
+.nf
+
+$ ./a.out "%m"
+Result string is "11"
+$ ./a.out "%5m"
+Result string is "00011"
+$ ./a.out "%_5m"
+Result string is " 11"
+.fi
.SH "SEE ALSO"
.BR date (1),
.BR time (2),