Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add utility function to get datetime.datetime from Time #1269

Open
tonynajjar opened this issue Apr 3, 2024 · 1 comment
Open

Add utility function to get datetime.datetime from Time #1269

tonynajjar opened this issue Apr 3, 2024 · 1 comment

Comments

@tonynajjar
Copy link
Contributor

tonynajjar commented Apr 3, 2024

Feature request

Feature description

I found myself needing to convert from rclpy's Time to datetime.datetime to input that in a third-party library. Would it make sense to add such a utility function? If so I could open a PR

Implementation considerations

I think it would just look like that:

return datetime.datetime.fromtimestamp(self._time_handle.nanoseconds / 1e9)

@tonynajjar tonynajjar changed the title Add utility function to get datetime.datetime from Timn Add utility function to get datetime.datetime from Time Apr 3, 2024
@gordon-n-stevenson
Copy link

This is an excellent idea, as I think it is a common issue when trying to timestamp out things and the management of the seconds/nanoseconds into a correct datetime can be challenging for new users.

It wouldn't be far off something like this SO answer - https://stackoverflow.com/questions/15649942/how-to-convert-epoch-time-with-nanoseconds-to-human-readable - but with the use of rclpy.Time right?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants