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 ?
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 :
also with date you can pretty it up to the format you want :
echo $(date --rfc-3339=seconds)
curl "http://worldtimeapi.org/api/ip" | jq
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:
the command i ran was: curl "http://worldtimeapi.org/api/timezone/Asia/Karachi.txt"
The APIs are available at the link: http://worldtimeapi.org/