
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 33676 Articles for Programming

4K+ Views
Whenever you want to add or subtract(apply an offset) to a date/time, use a datetime.datetime(), then add or subtract datetime.timedelta() instances. A timedelta object represents a duration, the difference between two dates or times. The timedelta constructor has the following function signature − datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]]) Note − All arguments are optional and default to 0. Arguments may be ints, longs, or floats, and may be positive or negative. You can read more about it here − https://docs.python.org/2/library/datetime.html#timedelta-objects Example An example of using the timedelta objects and dates − import datetime old_time = datetime.datetime.now() print(old_time) ... Read More

8K+ Views
Performing arithmetic operations on dates allows us to calculate differences between dates, add or subtract time intervals, or compare one date with another using the datetime module in Python. This article will discuss how to perform several arithmetic operations using the datetime module in Python. Adding and Subtracting Days Using timedelta In the Python datetime module, timedelta is a class that represents the difference or duration between two dates or times. We can use timedelta objects to perform date arithmetic, such as adding or subtracting a certain number of days, weeks, hours, minutes, etc. To add or subtract days, we ... Read More

4K+ Views
It is very easy to do date and time maths in Python using timedelta objects. Whenever you want to add or subtract to a date/time, use a datetime.datetime(), then add or subtract datetime.timedelta() instances. A timedelta object represents a duration, the difference between two dates or times. The timedelta constructor has the following function signature −datetime.timedelta([days[, seconds[, microseconds[, milliseconds[, minutes[, hours[, weeks]]]]]]])Note: All arguments are optional and default to 0. Arguments may be ints, longs, or floats, and may be positive or negative. You can read more about it here − https://docs.python.org/2/library/datetime.html#timedelta-objectsExampleAn example of using the timedelta objects and dates ... Read More

3K+ Views
In Python, measuring the execution time of a function or block of code can be done using several functions and methods provided by built-in modules like time and datetime. The following are the methods to measure the execution time of Python functions. Using time.time() Method Using time.process_time() Function Using datetime.now() Function Using time.time() Method The time.time() method (returns the current UTC) can measure how long a function takes to run. It returns the current time in seconds since January 1, 1970 (known as the Unix epoch). To ... Read More

8K+ Views
In Python, while working on date and time, converting time seconds to h:m:s (Hours: Minutes: Seconds) format can be done using simple arithmetic operations and built-in modules like datetime and time. The following are several ways to convert time seconds to h:m:s format. Using arithmetic operations (Naive Method) Using the timedelta class of the datetime module Using time.strftime() with time.gmtime() Using arithmetic operations (Naive method) This is the simplest way to convert seconds into time in H:M:S format. We use basic mathematical operations like division and modulo ... Read More

1K+ Views
A millisecond UNIX timestamp is a number that shows how many milliseconds have elapsed since the beginning of the Unix epoch, which is January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC) up to the current moment or specified date and time. Instead of counting time in days, hours, or minutes, it counts in milliseconds (1 second = 1000 milliseconds). In Python, the common way to convert a Datetime object to a milliseconds timestamp involves using the strptime() function (to parse a string into a Datetime object), then converting this datetime object into a UNIX timestamp by using the timestamp() method, ... Read More

270 Views
A timestamp represents a specific point in time as a numerical value. It typically measures the number of seconds that have elapsed since the Unix epoch, which is January 1, 1970, at 00:00:00 Coordinated Universal Time (UTC). The main reasons behind timestamp variations on different machines include differences in time zones, system clocks, locale settings, and the use of UTC and local time (such as IST, PST, or CET). In this article, we will explore timestamp differences across different machines by considering the following key factors. Different System Time Zones If each system were set to different time zones like ... Read More

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 string format in Python. ISO 8601 Date Format In Python, ISO 8601 date is represented as "YYYY-MM-DDTHH:MM:SS.mmmmmm" format. For example, August 25, 2023, is represented as 2023-08-25T14:35:45.123456. YYYY: Year (four digits) MM: Month (from 1-12) DD: Days (from ... Read More

6K+ Views
Python provides the time and datetime modules to convert a DateTime string into integer milliseconds. Key functions include time.time(), which gives the current time in seconds, and datetime.timestamp(), which converts datetime objects directly into seconds since the epoch. By multiplying these values by 1000, we can get the time in milliseconds. Using time.time() Method The time module in Python provides various methods and functions related to time. Here we use the time.time() method to get the current CPU time in seconds. The time is calculated since the epoch, which returns a floating-point number expressed in seconds. This value is multiplied ... Read More

819 Views
Both Python and JavaScript have unique ways of representing date and time data. To compare Python datetime objects with JavaScript Date objects, we must ensure that both are converted to a common format, such as ISO 8601 strings or Unix timestamps (milliseconds since epoch). The following are two major differences between Python (datetime) and JavaScript (date) objects. Month Representation: JavaScript uses a 0-indexed month (0 for January, 11 for December), while Python uses a 1-indexed month (1 for January, 12 for December). Default Time Zone: Python defaults to UTC, while JavaScript defaults to ... Read More