在不同的编程语言中查看当前时间的方法有所不同。以下是一些常见编程语言中查看当前时间的示例代码:
C++
```cpp
include include "time_cpp.h" int main() { time_cpp::Time now; std::cout << "现在的时间是:" << now.to_string() << std::endl; std::cout << "年份:" << now.year() << std::endl; std::cout << "月份:" << now.month() << std::endl; std::cout << "日期:" << now.day() << std::endl; std::cout << "小时:" << now.hour() << std::endl; std::cout << "分钟:" << now.minute() << std::endl; std::cout << "秒数:" << now.second() << std::endl; return 0; } ``` ```c include include int main() { time_t rawtime; struct tm * timeinfo; time(&rawtime); timeinfo = localtime(&rawtime); printf("当前日期: %02d-%02d-%04d\n", timeinfo->tm_mday, timeinfo->tm_mon + 1, timeinfo->tm_year + 1900); printf("当前时间: %02d:%02d:%02d\n", timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec); return 0; } ``` ```python from datetime import datetime now = datetime.now() print(now) ``` ```javascript var now = new Date(); console.log(now); ``` ```java import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; public class Main { public static void main(String[] args) { LocalDateTime now = LocalDateTime.now(); DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"); System.out.println(now.format(formatter)); } } ``` ```php $now = date("Y-m-d H:i:s"); echo $now; ``` 这些示例代码分别展示了如何在不同的编程语言中获取和显示当前时间。你可以根据自己的编程语言选择相应的代码来查看当前时间。C
Python
JavaScript
Java
PHP