Plenty have proposed a satisfactory solution. No one has come up with a solution that is satisfactory to you, because you have overconstrained the problem. The reason we still have no utctotimestamp() after all these years is that you, and you alone as far as I know, refuse to accept a method that inverts utcfromtimestamp() with microsecond precision over its working range. Such a method is a perfectly reasonable and acceptable solution and would add a lot of value to Python as a language.
I suspect you don't realize just how much pain you have unintentionally caused the world of Python users by singlehandedly blocking progress on this issue. I've seen them: students, friends, coworkers even very smart and capable people are stymied by it. No one thinks of looking in the calendar module. Maybe if you watched some of them struggle with this, you would understand.
# On the POSIX compliant platforms, `utcfromtimestamp(timestamp)` is
# equivalent to the following expression:
datetime(1970, 1, 1) + timedelta(seconds=timestamp)
# There is no method to obtain the timestamp from a `datetime` instance,
# but POSIX timestamp corresponding to a `datetime` instance `dt` can be
# easily calculated as follows. For a naive `dt`:
timestamp = (dt - datetime(1970, 1, 1)) / timedelta(seconds=1)
# And for an aware ``dt``::
timestamp = (dt - datetime(1970, 1, 1, tzinfo=timezone.utc)) / timedelta(seconds=1)
我确实记得关于这件事的一个discussion/bug report的事,而我不久前也在想这件事。长话短说:已经提出了很多建议,但由于某些原因,没有一个被接受。在
我认为最好用this reply来概括这一点:
这个故事的最终结果是documentation was added关于如何自己动手:
相关问题 更多 >
编程相关推荐