10 examples of 'get current time python' in Python

Every line of 'get current time python' 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
37def get_current_time():
38 return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.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

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
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
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()
43def get_gmt_time():
44 seconds = time.time() + 24 * 3600
45 st = time.localtime(seconds)
46 return time.strftime('%a, %d %b %Y %H:%M:%S GMT', st)
43def get_date (self):
44 cd = time.strftime ("%Y%m%d", time.localtime (time.time ()))
45 self.lock.acquire ()
46 if cd not in self.attain_status:
47 self.attain_status [cd] = 0
48 self.lock.release ()
49 return cd
306def get_time():
307 """
308 trivial wrapper around time.time to make testing easier
309 """
310 return time.time()
4def current_date_time():
5 time_format = "%Y-%m-%d %H:%M:%S"
6 return datetime.now().strftime(time_format)
11def get_time_str():
12 return time.strftime("%Y-%m-%d, %H:%M:%S ", time.localtime((time.time()) ))

Related snippets