How to convert YYYYMMDDHHMMSS to a date readable by `date`

前端 未结 6 376
执笔经年
执笔经年 2020-12-07 04:21

I have a set of date/time strings in the YYYYMMDDHHMMSS format that I want to convert to something readable by the date utility. Usually, I can do something li

6条回答
  •  暖寄归人
    2020-12-07 04:31

    What's with all of these regular expression answers? The date(1) tool has the ability to use strftime() style date formatting... an an example of converting one date type to another:

    $ date -j -f "%Y%m%d%H%M%S" "20100101123456" "+%Y-%m-%d %H:%M:%S"
    2010-01-01 12:34:56
    

    So if it's not in the format you want, convert it like that and then use it. If you just want to set it, you can simply do:

    $ date -f "%Y%m%d%H%M%S" "20100101123456"
    

提交回复
热议问题