Laravel  
laravel
文档
数据库
架构
入门
php技术
    
Laravelphp
laravel / php / java / vue / mysql / linux / python / javascript / html / css / c++ / c#

python time.strftime

作者:硝烟   发布日期:2025-05-29   浏览:48

import time

# 获取当前时间
current_time = time.localtime()

# 使用 time.strftime 格式化时间
formatted_time = time.strftime("%Y-%m-%d %H:%M:%S", current_time)

print("格式化后的时间为:", formatted_time)

解释说明:

  • time.localtime():获取当前时间,并将其转换为本地时间的结构化时间元组。
  • time.strftime(format, time_tuple):根据指定的格式字符串 format,将时间元组 time_tuple 转换为格式化后的字符串。
    • %Y:四位数的年份(例如:2023)。
    • %m:两位数的月份(01 到 12)。
    • %d:两位数的日期(01 到 31)。
    • %H:两位数的小时(00 到 23,24小时制)。
    • %M:两位数的分钟(00 到 59)。
    • %S:两位数的秒(00 到 59)。

上一篇:python处理数据

下一篇:python命令行参数

大家都在看

python时间格式

python ord和chr

python list.pop

python的for i in range

npm config set python

python代码简单

python读取文件夹

python中turtle

python 输出时间

python中list代表什么

Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3

Laravel 中文站