「C言語」setlocale関数でロケールを設定するサンプル

サンプルコード

#include <locale.h>
#include <stdio.h>
#include <time.h>
 
int main ()
{
   time_t currtime;
   struct tm *timer;
   char buffer[80];
 
   time( &currtime );
   timer = localtime( &currtime );
 
   printf("Locale is: %s\n", setlocale(LC_ALL, "en_GB.UTF-8"));
   strftime(buffer,80,"%c", timer );
   printf("Date is: %s\n", buffer);
 
  
   printf("Locale is: %s\n", setlocale(LC_ALL, "de_DE.UTF-8"));
   strftime(buffer,80,"%c", timer );
   printf("Date is: %s\n", buffer);
 
   return(0);
}

結果:
Locale is: en_GB
Date is: Thu 23 Aug 2019 06:39:32 MST
Locale is: de_DE
Date is: Do 23 Aug 2019 06:39:32 MST

 

C++

Posted by arkgame