Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialSahar Nasiri
7,454 PointsDon't get the question well
I searched the fromtimestamp(), what I got is, it takes a number of seconds as a time and return the year, day,... of that time, do I get right?
1 Answer
Chris Freeman
Treehouse Moderator 68,441 PointsBoth datetime
and date
objects have a fromtimestamp()
method that creates an object from a POSIX time value. POSIX time values are floats
.
The challenge asks: Create a function named timestamp_oldest that takes any number of POSIX timestamp arguments. Return the oldest one as a datetime object. Remember, POSIX timestamps are floats and lists have a .sort() method.
Stepping through this challenge:
from datetime import datetime
# Create a function named timestamp_oldest
# that takes any number of POSIX timestamp arguments.
# Use *args to take an arbitrary number of arguments
def timestamp_oldest(*args):
# Return the oldest one as a datetime object.
# Remember, POSIX timestamps are floats and lists have a .sort() method.
# create a list from args
times = list(args)
# sort the list
times.sort()
# oldest time has lowest value
# create date time from oldest value, return it
return datetime.fromtimestamp(times[0])
Jordan Bester
4,752 PointsJordan Bester
4,752 Pointschris would you mind further explaining the Posix timestamps?
Chris Freeman
Treehouse Moderator 68,441 PointsChris Freeman
Treehouse Moderator 68,441 PointsA POSIX timestamp is a floating point number representing the number of seconds since epoch time (see time docs) – January, 1970 on many systems.