ROS2 equivalent of rospy.Time.from_sec(...)

Where in ROS1 you could use rospy.Time.from_sec(...) to create a rospy.Time object representing 1 second, in ROS2 you can use rclpy.time.Time(seconds=...) to achieve a similar effect.

import rclpy.time
# 5 seconds after epoch
t = rclpy.time.Time(seconds=5.0)

Note that the nanoseconds argument is considered as nanoseconds after the seconds argument, so you can use it to specify fractions of a second:

import rclpy.time
# 5 seconds + 1 microsecond after Epoch
t = rclpy.time.Time(seconds=5.0, nanoseconds=1000)

As always, epoch refers to 1970-01-01 00:00:00 UTC.