python---将随机输入的时间格式字符串进行转换

简介: python---将随机输入的时间格式字符串进行转换

将随机输入的“2021-05-06 12:00“ 这种类型的时间格式字符串转化成“05/06/2021:12:00“此种形式。

time格式

strftime --数据结构格式转换为字符串格式

strptime  -- 从字符串类型时间(输入、传入)转换成时间的数据结构格式

需要将%Y-%m-%d %H:%M:%S格式字符串的转换为%m/%d/%Y:%H:%M格式。

import time

# time_array = "2021/05/31 00:44:33"

time_array = "2021-05-06 12:00"

time_array = time.strptime(time_array, "%Y-%m-%d %H:%M")

time_array = time.strftime("%m/%d/%Y:%H:%M", time_array)

print(time_array)

结果:

05/06/2021:12:00

相关文章
|
15天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
200 100
|
15天前
|
开发者 Python
Python中的f-string:高效字符串格式化的利器
Python中的f-string:高效字符串格式化的利器
242 99
|
19天前
|
Python
Python中的f-string:更优雅的字符串格式化
Python中的f-string:更优雅的字符串格式化
|
19天前
|
开发者 Python
Python f-strings:更优雅的字符串格式化技巧
Python f-strings:更优雅的字符串格式化技巧
|
19天前
|
开发者 Python
Python f-string:高效字符串格式化的艺术
Python f-string:高效字符串格式化的艺术
|
29天前
|
Python
使用Python f-strings实现更优雅的字符串格式化
使用Python f-strings实现更优雅的字符串格式化
|
2月前
|
Python
Python中的f-string:更简洁的字符串格式化
Python中的f-string:更简洁的字符串格式化
218 92
|
2月前
|
索引 Python
python 字符串的所有基础知识
python 字符串的所有基础知识
190 0
|
2月前
|
Python
Python字符串center()方法详解 - 实现字符串居中对齐的完整指南
Python的`center()`方法用于将字符串居中,并通过指定宽度和填充字符美化输出格式,常用于文本对齐、标题及表格设计。

推荐镜像

更多