2

How can I get time and date from internet using command line like when I type curl ipinfo.io it shows me my ip. Is there something for time and date as well ?

3 Answers 3

1

solution that does not require jq (not pre-packed) :

curl -s "http://worldtimeapi.org/api/ip" | cut -f12,13,14 -d ':' | cut -c 2-

if you don't necessarily need internet time then it would be :

echo $(date)

also with date you can pretty it up to the format you want :

echo $(date --rfc-3339=seconds)
0

worldtimeapi.org:

curl "http://worldtimeapi.org/api/ip" | jq
2
  • how do i know which websites would work for curl on command line ? Mar 22, 2019 at 12:53
  • you just have to know ...
    – pLumo
    Mar 22, 2019 at 12:53
0

You can access APIs thorough for fetching some data through curl like for extracting the date and time over the internet from command line I curled an api mentioned below:

http://worldtimeapi.org/api/timezone/:area/:location[/:region]

the command i ran was: curl "http://worldtimeapi.org/api/timezone/Asia/Karachi.txt"

The APIs are available at the link: http://worldtimeapi.org/

thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.