What do you want to save?
Add Code snippet
New code examples
-
Python 2021-10-24 02:57:16
fromat date string pyhton
from datetime import datetime now = datetime.now() # current date and time year = now.strftime("%Y") print("year:", year) month = now.strftime("%m") print("month:", month) day = now.strftime("%d") pri... Add solution -
Python 2021-10-23 14:14:06
datatime.strptime
from datetime import datetime dt_string = "12/11/2018 09:15:32" # Considering date is in dd/mm/yyyy format dt_object1 = datetime.strptime(dt_string, "%d/%m/%Y %H:%M:%S") print("dt_object1 =", dt_object1) # Considering dat... Add solution -
Python 2021-10-22 06:48:09
python find end of month
import calendar from datetime import datetime year = 2020 month = 1 rng = calendar.monthrange(year, month) # (2, 31) last_day = datetime(year, month, rng[1]) # calendar.monthrange returns tuple in the format of # (<day of week>, <last day>... Add solution -
Python 2021-10-21 16:10:12
how to convert time from one timezone to another in python
from datetime import datetime from pytz import timezone format = "%Y-%m-%d %H:%M:%S %Z%z" # Current time in UTC now_utc = datetime.now(timezone('UTC')) print(now_utc.strftime(format)) # Convert to Asia/Kolkata time zone now_asia = now_utc.astime... Add solution