// 引入 ctime 库
using namespace std;
int main() {
time_t timestamp = time(NULL);
struct tm datetime = *localtime(×tamp);
char output[50];
strftime(output, 50, "%B %e, %Y", &datetime);
cout << output << "\n";
strftime(output, 50, "%I:%M:%S %p", &datetime);
cout << output << "\n";
strftime(output, 50, "%m/%d/%y", &datetime);
cout << output << "\n";
strftime(output, 50, "%a %b %e %H:%M:%S %Y", &datetime);
cout << output << "\n";
return 0;
}
// 注意:此例显示的是服务器的本地时间,可能与您本地时间不同。