forked from Jayhello/python_utils
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_ope.py
More file actions
73 lines (53 loc) · 1.37 KB
/
Copy pathtime_ope.py
File metadata and controls
73 lines (53 loc) · 1.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# _*_ coding:utf-8 _*_
"""
get the seconds since epoch from the time + date output
function time consume
https://stackoverflow.com/questions/5478351/python-time-measure-function
"""
import time
import timeit
def test_time_consume():
start = time.clock()
time.sleep(1)
print time.clock() - start
# 0.999735009203
def timing(f):
def wrap(*args):
start = time.time()
ret = f(*args)
end = time.time()
print '%s function took %0.3f ms' % (f.func_name, (end - start) * 1000.0)
return ret
return wrap
@timing
def test_time():
time.sleep(1.1)
# test_time function took 1101.000 ms
def timeit_test():
timeit.timeit()
def sleep_milliseconds(mi_sec=50):
time.sleep(mi_sec / 1000.0)
@timing
def test_sp_mi_sec():
sleep_milliseconds()
def test_time_transform():
time_stamp = int(time.time())
s = '123'
print time_stamp
# 1509953402
print "%s_%s.pcm" % (s, time_stamp)
# 123_1509953402.pcm
s += str(time_stamp)
print s
print time.ctime(time_stamp)
# Mon Nov 06 15:30:02 2017
print time.strftime("%Y-%m-%d %H:%M:%S")
# 2017-11-09 17:17:02
print time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(1509953402))
# 2017-11-06 15:30:02
if __name__ == '__main__':
# test_time_consume()
# test_time()
# test_sp_mi_sec()
test_time_transform()
pass