Python獲取年月日


Python獲取年月日用到datetime模塊

獲取年月日
current_date = datetime.datetime.now().strftime('%Y-%m-%d')

獲取年月
current_date = datetime.datetime.now().strftime('%Y-%m')
current_date = datetime.datetime.now().date()

獲取年份
current_date = datetime.datetime.now().strftime('%Y')

第二種

d1 = datetime.date.today()
print(f'日期所屬的年份為 : {d1.year}')
print(f'日期所屬的月份為 : {d1.month}')
print(f'日期具體的日期號為 : {d1.day}')

  

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM