What do you want to save?
Add Code snippet
New code examples
-
Python 2021-09-30 23:04:03
utc to local time python
# here are a few ways to convert time zone from datetime import datetime from dateutil import tz # METHOD 1: Hardcode zones: from_zone = tz.gettz('UTC') to_zone = tz.gettz('America/New_York') # METHOD 2: Auto-detect zones: from_zone = tz.tzutc() to_zone... Add solution -
Python 2021-09-30 05:36:02
python date format
The program below converts a datetime object containing current date and time to different string formats. Code: from datetime import datetime now = datetime.now() # current date and time year = now.strftime("%Y") print("year:", ... Add solution -
Python 2021-09-28 20:56:03
ai virtual assistant
import os import time import webbrowser from datetime import date import playsound import speech_recognition as sr from gtts import gTTS import wikipedia from datetime import datetime WAKE = 'Sam' def speak111(text): tts = gTTS(text=text, lang=&quo... Add solution -
Python 2021-09-28 20:45:05
how to convert 24 hours to 12 hours in python
from datetime import datetime d = datetime.strptime("10:30", "%H:%M") print(d.strftime("%I:%M %p")) # outputs '10:30 AM' d = datetime.strptime("22:30", "%H:%M") print(d.strftime("%I:%M %p")) # ou... Add solution -
Python 2021-09-27 03:41:03
python time now other timezone
#as an aware datetime from datetime import datetime, timezone utc_dt = datetime.now(timezone.utc) # UTC time dt = utc_dt.astimezone() # local time #or from pytz database import pytz tz = pytz.timezone('Europe/Berlin') berlin_now = datetime.now(tz) Add solution -
Python 2021-09-26 17:19:06
convert date string to date time string python
from datetime import datetime datetime_str = '09/19/18 13:55:26' datetime_object = datetime.strptime(datetime_str, '%m/%d/%y %H:%M:%S') print(type(datetime_object)) print(datetime_object) # printed in default format Add solution