C++使用tm结构格式化时间

#include <iostream>
#include <ctime>

using namespace std;

int main() {
   // current date/time based on current system
   time_t now = time(0);

   cout << Number of sec since January 1,1970: << now << endl;

   tm *ltm = localtime(&now);

   // print various components of tm structure.
   cout << Year << 1970 + ltm->tm_year<<endl;
   cout << Month: << 1 + ltm->tm_mon<< endl;
   cout << Day: <<  ltm->tm_mday << endl;
   cout << Time: << 1 + ltm->tm_hour << :;
   cout << 1 + ltm->tm_min << :;
   cout << 1 + ltm->tm_sec << endl;
}

相关文章

#include <iostream> using namespace std; int mai...
#include <iostream> using namespace std; int mai...
// #include <iostream> using namespace std; int...
#include <iostream> #include <string> using...
#include <iostream> #include <cstring> usin...
#include <iostream> using namespace std; int mai...