| JSTRFTIME(3) | libjalali Manual | JSTRFTIME(3) |
jstrftime - format jalali date and time
#include <jtime.h>
size_t jstrftime(char *s, size_t max, const char *format,
const struct tm *jtm);
Link with -ljalali
The jstrftime() function formats the broken-down jalali time jtm according to the format specification format and places the result in the character array s of size max.
The format specification is a null-terminated string and may contain special character sequences called conversion specifications, each of which is introduced by a '%' character and terminated by some other character known as a conversion specifier character. All other character sequences are ordinary character sequences.
The characters of ordinary character sequences (including the null byte) are copied verbatim from format to s. However, the characters of conversion specifications are replaced as follows:
The broken-down time structure tm is defined in <jtime.h>. See also jctime(3).
The jstrftime() function returns the number of characters placed in the array s, not including the terminating null byte, provided the string, including the terminating null byte, fits. Otherwise, it returns max, and the contents of the array is undefined.
The environment variables TZ and LC_TIME are used.
C99.
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"
The program below can be used to experiment with jstrftime().
Some examples of the result string produced by the libjalali
implementation of jstrftime() are as follows:
$ ./a.out '%m' Result string is "11"
Here's the program source:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <jalali.h>
#include <jtime.h>
int
main(int argc, char *argv[])
{
char outstr[200];
time_t t;
struct tm *tmp;
t = time(NULL);
tmp = jlocaltime(&t);
if (tmp == NULL) {
perror("jlocaltime");
exit(EXIT_FAILURE);
}
if (jstrftime(outstr, sizeof(outstr), argv[1], tmp) == 0) {
fprintf(stderr, "jstrftime returned 0");
exit(EXIT_FAILURE);
}
printf("Result string is \"%s\"\n", outstr);
exit(EXIT_SUCCESS);
}
jdate(1), jcal(1), time(2), jctime(3), sprintf(3), jstrptime(3)
This page is part of release 0.2 of the libjalali man-pages
Written by Ashkan Ghassemi. <ghassemi@ftml.net>
Report libjalali bugs to <ghassemi@ftml.net>
libjalali home page: <http://savannah.nongnu.org/projects/jcal/>
Copyright (C) 2011 Ashkan Ghassemi.
License LGPLv3+: GNU LGPL version 3 or later <http://gnu.org/licenses/lgpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.
| 2011-05-28 | GNU |