#include <locale.h>   /* for setlocale()    */
#include <langinfo.h> /* for nl_langinfo()  */
#include <stdio.h>    /* for printf()       */
#include <stdlib.h>   /* for getenv()       */

int main(void) {
  char *loc, *oldloc;
  char *date_fmtstr;

  loc=getenv("LC_ALL");
  if (!loc) loc=getenv("LC_TIME");
  if (!loc) loc=getenv("LANG");
  if (!loc) {
	  printf("please set an appropriate locale environment variable!\n");
	  exit(1);
  }
  oldloc=setlocale(LC_TIME, loc); /* "" means get from environment */
  if (oldloc) {
    printf("successfully changed LC_TIME locale from %s to %s\n",oldloc,loc);
  } else {
    printf("failed to change LC_TIME locale from %s to %s\n",oldloc, loc);
  }

  date_fmtstr=nl_langinfo(D_FMT);
  printf("The format string we should use for the date is %s\n", date_fmtstr);
  return 0;
}
