datetime docs code example
Example 1: datetime python
from datetime import datetime as d
date = d.now()
print(date.strftime("%Y-%m-%d %H:%M:%S"))
Example 2: python datetime now
import datetime
print(datetime.datetime.now()) #datetime.datetime.now() is the syntax
Example 3: import time C#
using system.Threading
Example 4: date.month date time
import datetime
dt = datetime.datetime.today()
print dt.year
# Output: 2016
print dt.month
# Output: 8
print dt.day
# Output: 22
Example 5: datetime year python
import datetime
now = datetime.datetime.now()
print(now.year, now.month, now.day, now.hour, now.minute, now.second)
Example 6: datetime today
from datetime import datetime
# datetime object containing current date and time
now = datetime.now()
print("now =", now)
# dd/mm/YY H:M:S
dt_string = now.strftime("%d/%m/%Y %H:%M:%S")
print("date and time =", dt_string)