To get the current time in the format '2023-1-1 11:21:02', you can use the following Python code:

import datetime

now = datetime.datetime.now()
formatted_time = now.strftime("%Y-%-m-%-d %H:%M:%S")

print(formatted_time)

This code imports the datetime module and gets the current date and time using the now method. It then formats the time using the strftime method with the format string "%Y-%-m-%-d %H:%M:%S", which specifies the year, month, day, hour, minute, and second in the desired format. Finally, it prints the formatted time to the console.

Python: Get Current Time in 2023-1-1 11:21:02 Format

原文地址: https://www.cveoy.top/t/topic/otPY 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录