לדלג לתוכן

פייתון/פייתון גרסה 3/רשימת מודלים/datetime

מתוך ויקיספר, אוסף הספרים והמדריכים החופשי
>>>import time  
>>>import datetime  
>>>print("Current date and time: " , datetime.datetime.now())  
Current date and time:  2017-01-23 17:06:49.811339
>>>print("Current year: ", datetime.date.today().strftime("%Y"))
Current year:  2017  
>>>print("Month of year: ", datetime.date.today().strftime("%B")) 
Month of year:  January 
>>>print("Week number of the year: ", datetime.date.today().strftime("%W"))
Week number of the year:  04  
>>>print("Weekday of the week: ", datetime.date.today().strftime("%w"))  
Weekday of the week:  1
>>>print("Day of year: ", datetime.date.today().strftime("%j"))
Day of year:  023  
>>>print("Day of the month : ", datetime.date.today().strftime("%d")) 
Day of the month :  23 
>>>print("Day of week: ", datetime.date.today().strftime("%A")) 
Day of week:  Monday 
>>>print ("%s/%s/%s" % (now.year, now.month, now.day))
2017/1/23
>>>print ("%s:%s:%s" % (now.year, now.month, now.day))
2017:1:23
>>>print ("%s/%s/%s %s:%s:%s" % (now.year, now.month, now.day, now.hour, now.minute, now.second))
2017/1/23 17:17:43