w3resource

Python: Get the first and last second

Python Datetime: Exercise-52 with Solution

Write a Python program to get the first and last second.

Sample Solution:

Python Code:

# Import the datetime module
import datetime

# Print the minimum time (midnight) in the datetime module
print("First Second: ", datetime.time.min)
# Print the maximum time (11:59:59.999999) in the datetime module
print("Last Second: ", datetime.time.max)

Output:

First Second:  00:00:00                                                                                       
Last Second:  23:59:59.999999 

Explanation:

In the exercise above,

  • The code imports the "datetime" module, which provides classes for manipulating dates and times.
  • It prints the minimum time available in the datetime module using "datetime.time.min".
  • It prints the maximum time available in the datetime module using "datetime.time.max".

Flowchart:

Flowchart: Get the first and last second.

Python Code Editor:

Contribute your code and comments through Disqus.

Previous: Write a Python program to generate RFC 3339 timestamp.
Next: Write a Python program to validate a Gregorian date. The month is between 1 and 12 inclusive, the day is within the allowed number of days for the given month. Leap year’s are taken into consideration. The year is between 1 and 32767 inclusive.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://198.211.115.131/python-exercises/date-time-exercise/python-date-time-exercise-52.php