question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

General: add functionality to convert datetime object to timestamp

See original GitHub issue

Overview

we currently can convert a string in “MM-DD-YYYY HH:MM:SS” format. Want to add functionality of taking a datetime object and converting to a timestamp

Specification

date_time = datetime.datetime.fromisoformat("2020-10-15 12:00:00")
new_date_time_obj = date_time.replace(tzinfo=timezone.utc)
return int(new_date_time_obj.timestamp())

Dependencies

None

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
fubuloubucommented, Jan 27, 2022

timedelta might also be nice to add. I had thought about correcting the time for it, but that seems like it would lead to a lot of contextual errors. I think more directly just converting timedeltas (in string or datetime.timedelta object formats) to their integer equivalent in seconds:

int(timedelta.total_seconds())
0reactions
johnson2427commented, Jan 27, 2022

I can add timedelta to TimestampConverter. I will make a new issue

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Convert DateTime to UNIX Timestamp in Python
The datetime.now() function is used to obtain the current time. The mktime method is a time method that is the inverse function of...
Read more >
Python Timestamp With Examples - PYnative
We can convert a datetime object into a timestamp using the timestamp() method. If the datetime object is UTC aware, then this method...
Read more >
Converting datetime.date to UTC timestamp in Python
To convert datetime.datetime (not datetime.date ) object that already represents time in UTC to the corresponding POSIX timestamp (a float ).
Read more >
How do I convert a datetime to a UTC timestamp in Python?
You can use the datetime module to convert a datetime to a UTC ... This function returns the time since epoch for that...
Read more >
Python timestamp to datetime and vice-versa - Programiz
In this article, you will learn to convert timestamp to datetime object and datetime object to timestamp (with the help of examples).
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found