10 examples of 'python get current date' in Python

Every line of 'python get current date' 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
9def get_current_month_date():
10 today = date.today()
11 datem = date(today.year, today.month, 1)
12 return datem
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

71def getCurDate():
72 d = datetime.datetime.today()
73 year = d.year
74 month = d.month
75 month = str(0)+str(month) if month<10 else str(month)
76 day = d.day
77 day = str(0)+str(day) if day<10 else str(day)
78
79 date = (day)+(month)+str(year)
80
81 return date
37def get_current_time():
38 return time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time()))
4def current_date_time():
5 time_format = "%Y-%m-%d %H:%M:%S"
6 return datetime.now().strftime(time_format)
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
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
32def date():
33 return datetime.now()
10def get_prev_month_date():
11 today = date.today()
12 if today.day == 1:
13 if today.month == 1:
14 date_month = date(today.year - 1, 12, 1)
15 else:
16 date_month = date(today.year, today.month - 1, 1)
17 else:
18 date_month = date(today.year, today.month, 1)
19 return date_month
71def get_today(self):
72 return datetime.datetime.today().date()
41def date():
42 return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")

Related snippets