使用句点格式化日期和时间作为分隔符

时间:2016-06-03 17:38:00

标签: python

我正在尝试使用Python在Windows应用程序中应用当前时间和日期。我使用了以下代码:

current_time = str(time.strftime("%m.%d.%Y %H:%M"))

type(waitForObject("{name='TextBoxSampleName'}"), "Test." + current_time)

但是当我运行脚本时,我看到以下格式

27Test.06.03.2016 10(小时和分钟因某种原因分开)

我希望最终结果为Test.06.03.2016.10:27

1 个答案:

答案 0 :(得分:0)

在不知道waitForObject是什么的情况下,我们仍然可以获得您想要的输出。

首先,current_time =行中存在轻微的格式错误:

current_time = str(time.strftime("%m.%d.%Y.%H:%M"))
                                          ^-- Add this period to get the format you want

接下来,第二行可以简单地(或者您可以将其分配给变量供以后使用):

print("Test."+current_time)

这两个更改将打印出如下内容:

Test.06.03.2016.12:42