How to format the date in KornShell script to DD-MON-YYYY?

前端 未结 3 1793
独厮守ぢ
独厮守ぢ 2021-01-19 12:32

How do I format a date in a KornShell (ksh) script to DD-MON-YYYY?

I have tried the following:

date \'+%d-%h-%Y\'

It returns

3条回答
  •  -上瘾入骨i
    2021-01-19 13:15

    The ^ character forces uppercase in the GNU coreutils date (at least, it does in version 6.9.92.4 of coreutils):

    $ date '+%d-%^h-%Y'
    04-NOV-2009
    

    Unfortunately, ^ is not POSIX standard for date, so you'll probably have to resort to a second command such as the tr suggested by @martin clayton, if you aren't on a GNU system.

提交回复
热议问题