1
我想在不同的語言環境中使用C++打印時間戳,我在一個特定主機上得到了fr_FR的奇怪輸出。C++ strftime%b不能按預期工作
下面是代碼,
#include <time.h> /* time_t, struct tm, time, localtime, strftime */
#include <stdlib.h>
#include <locale.h>
#include <clocale>
#include <iostream>
using namespace std;
int main()
{
time_t rawtime;
struct tm * timeinfo;
char buffer [32];
setlocale(LC_ALL, "");
cout << "LC_ALL: " << setlocale(LC_ALL, NULL) << endl;
cout << "LC_CTYPE: " << setlocale(LC_CTYPE, NULL) << endl;
time (&rawtime);
timeinfo = localtime (&rawtime);
strftime (buffer,sizeof(buffer),"%a %b %d %H:%M:%S %Y %Z",timeinfo);
puts (buffer);
return 0;
}
運行上面的程序我做
export LANG=fr_FR.ISO8859-1
它給輸出,
LC_ALL: fr_FR.ISO8859-1
LC_CTYPE: fr_FR.ISO8859-1
ven. avril 12 08:49:55 2013 UTC
它提供了相同的輸出,既%B之前和%B,當我檢查另一臺機器時,它按預期工作。輸出,
LC_ALL: fr_FR.ISO8859-1
LC_CTYPE: fr_FR.ISO8859-1
jeu avr 11 23:26:24 2013 PDT
在一臺機器,
$date +%b
avr
$date +%B
avril
在problamatic機,
$date +%b
avril
$date +%B
avril
請幫我解決這個問題。
每臺機器的操作系統是什麼? –
這兩臺機器都是RHEL5。 –