About 162,000 results
Open links in new tab
  1. datetime - How do I get the current time in Python ... - Stack …

    datetime module. The datetime module is also quite useful here: >>> import datetime datetime.datetime.now. The datetime.now is a class method that returns the current time. It …

  2. How do I find the time difference between two datetime objects in …

    Aug 28, 2009 · import datetime date = datetime.date(1, 1, 1) #combine a dummy date to the time datetime1 = datetime.datetime.combine(date, start_time) datetime2 = …

  3. Getting today's date in YYYY-MM-DD in Python? - Stack Overflow

    Sep 9, 2015 · This module is clever enough to understand ... from python 3.11 onward; from datetime import datetime, UTC ...

  4. datetime - How to get UTC time in Python? - Stack Overflow

    Apr 11, 2013 · For Python 3, use datetime.now(timezone.utc) to get a timezone-aware datetime, and use .timestamp() to convert it to a timestamp. from datetime import datetime, timezone …

  5. datetime - Python Timezone conversion - Stack Overflow

    Jun 12, 2012 · To convert a time in one timezone to another timezone in Python, you could use datetime.astimezone(): so, below code is to convert the local time to other time zone. …

  6. Python - Get Yesterday's date as a string in YYYY-MM-DD format

    Nov 18, 2016 · You just need to subtract one day from today's date. In Python datetime.timedelta object lets you create specific spans of time as a timedelta object. datetime.timedelta(1) gives …

  7. How can I specify date and time in Python? - Stack Overflow

    Apr 10, 2022 · What is the object used in Python to specify date (and time) in Python? For instance, to create an object that holds a given date and time, (let's say '05/10/09 18:00').

  8. The correct way to import and use the datetime python library

    Mar 18, 2012 · The datetime module contains a number of classes, including the class datetime.datetime. If you don't care about the other functions in the module, you can write: …

  9. datetime - Creating a range of dates in Python - Stack Overflow

    Jun 14, 2009 · You can write a generator function that returns date objects starting from today: import datetime def date_generator(): from_date = datetime.datetime.today() while True: yield …

  10. Difference between Python datetime vs time modules

    Aug 15, 2017 · This can also be done using datetime, but if we are only dealing with time for a particular day, then time module can be used. Datetime is used to store a particular data and …

Refresh