1

I am trying to get the current date by below python code

from datetime import date
currentdate = date.today()

This returns me the system date, so if I try to change the system date it returns the current date based on that. But I want to get the current date regardless of system date so that if we change the system date as well it should return me the current date. How can I achive this in python?

9
  • are you talking about time based on your timezone kinda thing? Commented Aug 24, 2021 at 8:24
  • @GhostOps yes based on my timezone . Commented Aug 24, 2021 at 8:26
  • try pytz library then.. Commented Aug 24, 2021 at 8:32
  • @GhostOps If I am not connected to internet is there any way to get currentdate? Commented Aug 24, 2021 at 9:44
  • @Tomerikoo with this approach it returns date based on system date right i do not want it to be our systemdate it should be based on timezone Commented Aug 24, 2021 at 9:46

1 Answer 1

2

You should get current time from outer source, like

r = requests.get('http://worldclockapi.com/api/json/utc/now').json()
print(r['currentDateTime']);
Sign up to request clarification or add additional context in comments.

2 Comments

If I am not connected to internet is there any way to get currentdate?
then you have no outer source, and only thing you can use is system time — UTC or Local

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.