欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

[祖传代码] 获取当前时间(日期)字符串

程序员文章站 2022-07-14 19:46:24
...

Python 3 代码片

import time

dateStr = time.strftime('%Y%m%d', time.localtime(time.time()))
print(dateStr)

常用于给文件和目录命名。这里顺手检查目录是否存在,不存在就建立目录:

import os

localDir = "xxxxx"
if not os.path.exist(localDir):
    os.makedirs(localDir)

—— 写代码应该要像拼积木,自己的积木块越多,拼的玩具越有趣。