Путеводитель по Руководству Linux

  User  |  Syst  |  Libr  |  Device  |  Files  |  Other  |  Admin  |  Head  |



   strftime    ( 3 )

формат даты и времени (format date and time)

  Name  |  Synopsis  |  Description  |  Return value  |  Environment  |  Attributes  |  Conforming to  |  Note  |  Bugs  |    Examples    |  See also  |

Примеры (Examples)

RFC 2822-compliant date format (with an English locale for %a and
       %b)

"%a, %d %b %Y %T %z"

RFC 822-compliant date format (with an English locale for %a and %b)

"%a, %d %b %y %T %z"

Example program The program below can be used to experiment with strftime().

Some examples of the result string produced by the glibc implementation of strftime() are as follows:

$ ./a.out '%m' Result string is "11" $ ./a.out '%5m' Result string is "00011" $ ./a.out '%_5m' Result string is " 11"

Program source

#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); }