I am getting date in one of file in the format "Fri Feb 25 16:07:17 UTC 2022" Which I want to convert it to "2022-02-25 16:07:17". However I am able to do it using Python but its being long process to call python from shell script and getting that variable back.

Just I am looking for simple option to convert "Fri Feb 25 16:07:17 UTC 2022" it to "2022-02-25 16:07:17" using bash shell script.

  • Thanks @Panki I have updated the question Feb 25, 2022 at 18:05
  • 1
    To be pedantic, bash itself cannot do this. You have to some some external command. date or python are both external tools. Feb 25, 2022 at 20:54
  • thanks @glennjackman, I used the below provided answer by Panki, Its working fine for me. Actually i wanted to get rid of using Python inside the shell and it was being overhead just for date conversion. Feb 26, 2022 at 4:21

1 Answer 1


You can use date for this task.

mydate="Fri Feb 25 16:07:17 UTC 2022"
date -u -d "$mydate" "+%F %T"

-u tells date to output the result in UTC. See man date for more formatting options.

  • Thanks its working perfectly . Feb 25, 2022 at 18:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .