Convert string to date in bash

前端 未结 4 515
挽巷
挽巷 2020-12-08 04:19

I have a string in the format \"yyyymmdd\". It is a string in bash and I want to get it converted into a date so that all other date functions can be used on it.

\"2

4条回答
  •  囚心锁ツ
    2020-12-08 04:39

    date only work with GNU date (usually comes with Linux)

    for OS X, two choices:

    1. change command (verified)

      #!/bin/sh
      #DATE=20090801204150
      #date -jf "%Y%m%d%H%M%S" $DATE "+date \"%A,%_d %B %Y %H:%M:%S\""
      date "Saturday, 1 August 2009 20:41:50"
      

      http://www.unix.com/shell-programming-and-scripting/116310-date-conversion.html

    2. Download the GNU Utilities from Coreutils - GNU core utilities (not verified yet) http://www.unix.com/emergency-unix-and-linux-support/199565-convert-string-date-add-1-a.html

提交回复
热议问题