运行 ❯
获取您自己的网站
×
更改方向
更改主题,深色/浅色
转到 Spaces
#include <iostream> #include <ctime> // Import the ctime library 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; } // Note: This example displays the server's local time, which may differ from your local time.
格式化的日期和时间