SaiKrishna Tavva has Published 98 Articles

How do I get an ISO 8601 date in string format in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 16-Jun-2025 15:47:20

64K+ Views

The ISO 8601 standard defines an internationally recognised format for representing dates and times. ISO 8601 is a date and time format that helps remove different forms of the day, date, and time conventions worldwide. In this article, we will discuss several methods to get an ISO 8601 date in ... Read More

How do I get time of a Python program\'s execution?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 03-Jun-2025 16:34:47

505 Views

Python provides different ways to find the execution time taken by a script or specific parts of the code such as using the functions from the time module, like time.time() or time.clock(). The following are some common methods used to measure execution time in Python: Using ... Read More

How to measure time with high-precision in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 03-Jun-2025 16:17:28

5K+ Views

Python provides various modules, such as time, datetime, and timeit, to measure time with high accuracy. These modules offer high-resolution clocks to measure time intervals. The following are several methods used to measure time with high precision in Python. Using time.time() Method ... Read More

How to prepare a Python date object to be inserted into MongoDB?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 03-Jun-2025 15:12:08

2K+ Views

We can use the PyMongo library (the official Mongodb driver for Python) to connect to a Mongodb database and use it to insert, update, delete, etc objects. To include date and time information, Mongodb supports ISODate format, and PyMongo provides direct support for Python's datetime.datetime objects. There are multiple ways ... Read More

How do I convert a datetime to a UTC timestamp in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 19-May-2025 17:56:03

36K+ Views

We can use the datetime module to convert a datetime to a UTC timestamp in Python. If we already have the datetime object in UTC, then the timestamp() function can be directly used to get a UTC timestamp. This function returns the time since epoch for that datetime object. If we ... Read More

How to compare calendar.timegm() vs. time.mktime() in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 19-May-2025 17:37:30

981 Views

In Python, the mktime() function (from the time module) assumes that the passed tuple is in local time, while the calendar.timegm() (from the calendar module) assumes it's in GMT/UTC. Depending on the interpretation, the tuple represents a different time, so both functions return different values (seconds since the epoch are UTC-based). The difference between the ... Read More

How does nested character class subtraction work in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 15-May-2025 19:42:08

391 Views

Nested character class subtraction in Python's regular expressions allows us to define complex character sets by removing characters from an existing character class, including another character class by using the '-' operator. It works from the innermost to outermost character class, and subtractions are evaluated from left to right ... Read More

What are negated character classes that are used in Python regular expressions?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 15-May-2025 19:40:32

1K+ Views

 While working with Python regex,  if we want to match everything except certain characters, then we can use negated character classes by placing a caret (^) as the first character inside square brackets. The pattern [^abdfgh] will match any character not in that set. What is a Negated Character Class? ... Read More

Which one is more accurate in between time.clock() vs. time.time()?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 15-May-2025 19:38:13

552 Views

Two commonly used functions from the Python time module are time.time() and time.clock(). Each function provides a different purpose and returns different values depending on the platform (Windows vs. Unix). In Python 3.8, time.clock() was removed, so time.perf_counter() or time.process_time() are generally preferred over the older time.clock() for specific CPU time measurements. ... Read More

How to convert timestamp string to datetime object in Python?

SaiKrishna Tavva

SaiKrishna Tavva

Updated on 15-May-2025 18:49:39

23K+ Views

In many real-world applications, timestamps are used to represent dates and times, but they are not human-readable. To make them understandable or use them in various datetime manipulations, it’s essential to convert them into Python’s datetime object. Python’s datetime module provides multiple functions to convert timestamps to datetime objects. Below ... Read More

1 2 3 4 5 ... 10 Next
Advertisements