私はCに新しく、strptime
関数を試しています。これは文字列の時刻を構造体tm
に変換します。変換後、私は正当な時を得ていない。すべて正常ですが、年は間違って表示されています(デフォルトの1900年)。strptimeはタイムゾーン形式指定子では機能しません
#include <stdio.h>
#include <time.h>
#include <string.h>
#include <ctype.h>
int main()
{
struct tm tm;
char *pszTemp = "Mon Apr 25 09:53:00 IST 2016";
char szTempBuffer[256];
memset(&tm, 0, sizeof(struct tm));
memset(szTempBuffer, 0, sizeof(szTempBuffer));
strptime(pszTemp, "%a %b %d %H:%M:%S %Z %Y", &tm);
strftime(szTempBuffer, sizeof(szTempBuffer), "%Y-%m-%d %H:%M:%S", &tm);
printf("Last Boot Time after parsed = %s\n", szTempBuffer);
return 0;
}
出力:1900年4月25日9時53分00秒
['strptime'](http://man7.org/linux/man-pages/man3/strptime.3.html)が返すものを確認しましたか? NULLポインタを返さないようにするには? –
'-Wall'オプションでコンパイルしようとしましたか? – LPs
@LP:動作しませんでした。 –