Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 10

Python Exercise Example 10

Python 100 Examples Python 100 Examples

**Question:** Pause for one second before output, and format the current time.

**Analysis:** None.

Program source code:

Example

#!/usr/bin/python

-- coding: UTF-8 --

import

time

print

(

time

.

strftime

(

'

%Y-%m-%d %H:%M:%S

'

,

time

.

localtime

(

time

.

time

(

)

)

)

)

Pause for one second

time

.

sleep

(

1

)

print

(

time

.

strftime

(

'

%Y-%m-%d %H:%M:%S

'

,

time

.

localtime

(

time

.

time

(

)

)

)

)

The output of the above example is:


2015-10-21 17:48:40
2015-10-21 17:48:41

Python 100 Examples Python 100 Examples