get UTC time directly from a website in python
up vote
0
down vote
favorite
i want to get the utc time directly from a website that can give that. and i don't want to use python modules because they give me the system time and my system time does not show the correct time.
how can i get the correct utc time without changing the system time?
i use
import ntplib,datetime
x = ntplib.NTPClient()
datetime.datetime.utcfromtimestamp(x.request('europe.pool.ntp.org').tx_time)
but i get this error
raise NTPException("No response received from %s." % host)
ntplib.NTPException: No response received from europe.pool.ntp.org.
python utc
add a comment |
up vote
0
down vote
favorite
i want to get the utc time directly from a website that can give that. and i don't want to use python modules because they give me the system time and my system time does not show the correct time.
how can i get the correct utc time without changing the system time?
i use
import ntplib,datetime
x = ntplib.NTPClient()
datetime.datetime.utcfromtimestamp(x.request('europe.pool.ntp.org').tx_time)
but i get this error
raise NTPException("No response received from %s." % host)
ntplib.NTPException: No response received from europe.pool.ntp.org.
python utc
1
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
i want to get the utc time directly from a website that can give that. and i don't want to use python modules because they give me the system time and my system time does not show the correct time.
how can i get the correct utc time without changing the system time?
i use
import ntplib,datetime
x = ntplib.NTPClient()
datetime.datetime.utcfromtimestamp(x.request('europe.pool.ntp.org').tx_time)
but i get this error
raise NTPException("No response received from %s." % host)
ntplib.NTPException: No response received from europe.pool.ntp.org.
python utc
i want to get the utc time directly from a website that can give that. and i don't want to use python modules because they give me the system time and my system time does not show the correct time.
how can i get the correct utc time without changing the system time?
i use
import ntplib,datetime
x = ntplib.NTPClient()
datetime.datetime.utcfromtimestamp(x.request('europe.pool.ntp.org').tx_time)
but i get this error
raise NTPException("No response received from %s." % host)
ntplib.NTPException: No response received from europe.pool.ntp.org.
python utc
python utc
edited 16 hours ago
Sufiyan Ghori
10.7k95580
10.7k95580
asked 16 hours ago
ali
32
32
1
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago
add a comment |
1
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago
1
1
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
Could you try to call datetime.utcnow()
? From the python docs
Here is my output
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 4, 9, 47, 59, 572104)
Edit as OP having issues with above
As for a web based solution, this works fine for me (Whilst avoiding your website
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> print(x.content)
b'abbreviation: GMTndatetime: 2018-11-04T10:09:18.395273+00:00nday_of_week: 0nday_of_year: 308ndst: falsendst_from: ndst_until: ntimezone: Europe/Londonnunixtime: 1541326158nutc_offset: +00:00nweek_number: 44'
Update
You can get the datetime like so. I am certain there is a better way to do this, but this method works fine for this specific use-case.
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> y = x.text
>>> print(y[27:47])
2018-11-04T11:01:46
New contributor
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
Could you try to call datetime.utcnow()
? From the python docs
Here is my output
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 4, 9, 47, 59, 572104)
Edit as OP having issues with above
As for a web based solution, this works fine for me (Whilst avoiding your website
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> print(x.content)
b'abbreviation: GMTndatetime: 2018-11-04T10:09:18.395273+00:00nday_of_week: 0nday_of_year: 308ndst: falsendst_from: ndst_until: ntimezone: Europe/Londonnunixtime: 1541326158nutc_offset: +00:00nweek_number: 44'
Update
You can get the datetime like so. I am certain there is a better way to do this, but this method works fine for this specific use-case.
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> y = x.text
>>> print(y[27:47])
2018-11-04T11:01:46
New contributor
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
add a comment |
up vote
0
down vote
accepted
Could you try to call datetime.utcnow()
? From the python docs
Here is my output
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 4, 9, 47, 59, 572104)
Edit as OP having issues with above
As for a web based solution, this works fine for me (Whilst avoiding your website
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> print(x.content)
b'abbreviation: GMTndatetime: 2018-11-04T10:09:18.395273+00:00nday_of_week: 0nday_of_year: 308ndst: falsendst_from: ndst_until: ntimezone: Europe/Londonnunixtime: 1541326158nutc_offset: +00:00nweek_number: 44'
Update
You can get the datetime like so. I am certain there is a better way to do this, but this method works fine for this specific use-case.
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> y = x.text
>>> print(y[27:47])
2018-11-04T11:01:46
New contributor
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
Could you try to call datetime.utcnow()
? From the python docs
Here is my output
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 4, 9, 47, 59, 572104)
Edit as OP having issues with above
As for a web based solution, this works fine for me (Whilst avoiding your website
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> print(x.content)
b'abbreviation: GMTndatetime: 2018-11-04T10:09:18.395273+00:00nday_of_week: 0nday_of_year: 308ndst: falsendst_from: ndst_until: ntimezone: Europe/Londonnunixtime: 1541326158nutc_offset: +00:00nweek_number: 44'
Update
You can get the datetime like so. I am certain there is a better way to do this, but this method works fine for this specific use-case.
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> y = x.text
>>> print(y[27:47])
2018-11-04T11:01:46
New contributor
Could you try to call datetime.utcnow()
? From the python docs
Here is my output
>>> import datetime
>>> datetime.datetime.utcnow()
datetime.datetime(2018, 11, 4, 9, 47, 59, 572104)
Edit as OP having issues with above
As for a web based solution, this works fine for me (Whilst avoiding your website
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> print(x.content)
b'abbreviation: GMTndatetime: 2018-11-04T10:09:18.395273+00:00nday_of_week: 0nday_of_year: 308ndst: falsendst_from: ndst_until: ntimezone: Europe/Londonnunixtime: 1541326158nutc_offset: +00:00nweek_number: 44'
Update
You can get the datetime like so. I am certain there is a better way to do this, but this method works fine for this specific use-case.
>>> import requests
>>> x = requests.get('http://worldtimeapi.org/api/timezone/Europe/London.txt')
>>> y = x.text
>>> print(y[27:47])
2018-11-04T11:01:46
New contributor
edited 15 hours ago
New contributor
answered 16 hours ago
BGlasbey
385
385
New contributor
New contributor
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
add a comment |
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
i try that and it gives me the system time which i use. and my system doesn't show the correct time.i want to receive correct time although my system doesn't set on the correct time.
– ali
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
It should give you utc time. I will update my answer with a web-based solution also.
– BGlasbey
16 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
thank you it works. could you tell me how can i separate the unix time and put it in a separate variable?
– ali
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
Updated for you.
– BGlasbey
15 hours ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53139354%2fget-utc-time-directly-from-a-website-in-python%23new-answer', 'question_page');
}
);
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
are you behind a proxy? it works for me.
– Sufiyan Ghori
16 hours ago
@Sufiyan Ghori yes. is there another website that i can replace in this code?or any other way for this question?
– ali
16 hours ago
FWIW, this should really be fixed by installing an NTP client as a constant background service on the machine to keep the actual machine time accurate, if at all possible.
– deceze♦
16 hours ago
From the response looks like site is not reachable from your computer. I tried the same code from my local desktop and it worked fine.
– vikas singhal
16 hours ago