Parse Date in Bash

前端 未结 10 1674
灰色年华
灰色年华 2020-11-29 02:17

How would you parse a date in bash, with separate fields (years, months, days, hours, minutes, seconds) into different variables?

The date format is: YYYY-MM-D

10条回答
  •  佛祖请我去吃肉
    2020-11-29 02:55

    The array method is perhaps better, but this is what you were specifically asking for:

    IFS=" :-"
    read year month day hour minute second < <(echo "YYYY-MM-DD hh:mm:ss")
    

提交回复
热议问题