10 examples of 'python get current time in seconds' in Python

Every line of 'python get current time in seconds' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
78def get_current_time():
79 error_time = int(time.time()) # ->这是时间戳
80 error_time = time.localtime(error_time)
81 other_style_time = time.strftime("%Y-%m-%d %H:%M:%S", error_time)
82 return other_style_time
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

5def get_time():
6 return int(time.time())
37def get_current_time():
38 return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
17def get_current_time(self):
18 return datetime.datetime.now()
28@staticmethod
29def get_current_time():
30 """获取当前时间"""
31 try:
32 time = datetime.now()
33 current_time = time.strftime('%H_%M_%S')
34 except Exception as e:
35 raise e
36 else:
37 return current_time
306def get_time():
307 """
308 trivial wrapper around time.time to make testing easier
309 """
310 return time.time()
4def ms_time():
5 return int(time.time() * 1000)
528def current_time():
529 '''
530 Return the current time in ISO format
531
532 CLI Example:
533
534 .. code-block:: bash
535
536 salt '*' status.current_time
537 '''
538 return datetime.datetime.now().isoformat()
77def get_time():
78 return time.clock()
16def get_time(self):
17 # 'yyyy-mm-dd'
18 return str(datetime.datetime.now()).split(' ')[0]

Related snippets