在VS编程时,你可以使用C++标准库中的`
```cpp
include include int main() { // 获取当前时间戳 time_t now = time(NULL); // 将时间戳转换为本地时间结构 struct tm systime; localtime_s(&systime, &now); // 输出年、月、日、时、分、秒 std::cout << "当前时间:" << std::endl; std::cout << "年: " << 1900 + systime.tm_year << std::endl; std::cout << "月: " << 1 + systime.tm_mon << std::endl; std::cout << "日: " << systime.tm_mday << std::endl; std::cout << "时: " << systime.tm_hour << std::endl; std::cout << "分: " << systime.tm_min << std::endl; std::cout << "秒: " << systime.tm_sec << std::endl; return 0; } ``` 在这个示例中,我们首先使用`time(NULL)`获取当前时间戳,然后使用`localtime_s`函数将时间戳转换为本地时间结构`tm`。最后,我们输出年、月、日、时、分、秒等各个组成部分。 运行这段代码,你将在VS的控制台上看到当前日期和时间。