I want to get the Date and Time of The Current Location. If somebody runs the code in a different country thought it will show the date and and time for them, and not for me. If you know any commands for this please put the down bellow. I prefer If I don't need a library so that people who get the code don't need to download the library.
Asked
Active
Viewed 1,658 times
0
-
The standard Python library has `datetime.datetime.now()`. That returns the time and date of the computer it is running on, and can also handle other timezones. If that's not what you are looking for you need to be clear how the end user and the computer where the code is running are related to one another. – Martijn Pieters Jul 19 '19 at 19:20
2 Answers
3
I think you can not get the date or time of a location.
This code gets your device's date and time:
from datetime import datetime
now = datetime.now()
current_time = now.strftime("%H:%M:%S")
current_date = now.strftime("%D")
print("Current Time: ", current_time)
print("Current Date: ", current_date)

bapap
- 514
- 8
- 25
1
A standard Python module called datetime can probably help you with retrieving the current system date and time from where the program is run Since it's a standard module, there would be no need to install it rather just import it in the program itself.
Example :
import datetime
x = datetime.datetime.now()
print(x)
Would give you the output as :
2019-07-20 00:52:27.158746
The above output contains the current year, month, day, hour, minute, second, and microsecond.

Alen S Thomas
- 923
- 7
- 10