I am aware of the datetime library. However, on top of knowing the date and time of the world, I also need to know the date and time of the local server my application will be running on. The reason for this is because my local server is not connected to the internet so it may have a different date and time and I want to be able to detect it if that's the case. Any help would be appreciated.
Asked
Active
Viewed 5,656 times
2 Answers
5
With the datetime
package, as you refer to, you can get the current local time e.g. by
import datetime
now = datetime.datetime.now()
print(now)
This is the local time on the machine. Python does not reach out to the world over the internet to ask what time it is.

jmd_dk
- 12,125
- 9
- 63
- 94
-
Thanks for the reply. I may have phrased it wrong. Even if python gets the time from the local machine, the time is still set by default via internet. However, if I need the time for a local server that my machine is connected to. It just hit me that I may need to set up a socket to receive the information from the server. – Zarif Akhtab Dec 28 '16 at 19:20
1
There is also the time
module which has a localtime
method. However this just reformats time
.
import time
localTime = time.localtime()
print (localTime)

Frank
- 735
- 1
- 12
- 33