Formatting the date in unix to include suffix on day (st, nd, rd and th)

后端 未结 3 1070
半阙折子戏
半阙折子戏 2021-02-15 00:26

How can I add the suffix on the day number of a unix date?

I\'ll explain. I have a TextMate bundle snippit that writes out today\'s date. It uses unix date and

3条回答
  •  栀梦
    栀梦 (楼主)
    2021-02-15 01:06

    Try.

    #!/bin/sh
    DaySuffix() {
      case `date +%d` in
        1|21|31) echo "st";;
        2|22)    echo "nd";;
        3|23)    echo "rd";;
        *)       echo "th";;
      esac
    }
    date "+%A %d`DaySuffix` %B %Y"
    

提交回复
热议问题