Copyright © 2008-2018, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Date: 2018may14 Language: C/C++ Q. C/C++: How do I display the 4-digit year? A. Use#include <time.h> char buf; struct tm here; const time_t now = time(NULL); localtime_r(&now, &here); strftime(buf, size(buf), "%Y", &here); // You almost certainly don't want %G.Orsnprintf(buf, sizeof(buf), "%d", here->tm_year + 1900); // Don't forget to add 1900Hacker News discusssion. https://news.ycombinator.com/item?id=17066739
Add a commentSign in to add a comment