What is the module/method used to get the current time?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
If you are using NumPy already then directly you can use the numpy.datetime64() function.
For only the date:
Or, if you are using Pandas already then you can use the pandas.to_datetime() function:
Or:
Using Pandas to get the current time, kind of over killing the problem at hand:
Output:
I want to get the time with milliseconds. A simple way to get them:
But I want only milliseconds, right? The shortest way to get them:
Add or remove zeroes from the last multiplication to adjust number of decimal points, or just:
Why not ask the U.S. Naval Observatory, the official timekeeper of the United States Navy?
If you live in the D.C. area (like me) the latency might not be too bad...
Try the arrow module from http://crsmithdev.com/arrow/:
Or the UTC version:
To change its output, add .format():
For a specific timezone:
An hour ago:
Or if you want the gist.