无法在bash mac中格式化日期 [英] Cannot format date in bash mac

查看:55
本文介绍了无法在bash mac中格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

输入: $ date -d '13 JAN 1995'+%A
输出:

input: $ date -d '13 JAN 1995' +%A
output:

usage: date [-jnRu] [-d dst] [-r seconds] [-t west] [-v[+|-]val[ymwdHMS]] ... 
            [-f fmt date | [[[mm]dd]HH]MM[[cc]yy][.ss]] [+format]

预期输出:星期五

首先,我认为这是因为我的bash 3.x版本较旧,但后来我升级到了5.0.仍然有这个问题.

First I thought this is because of my older version of bash 3.x but later I upgraded to 5.0. Still having this problem.

我在这里阅读了日期格式将日期格式转换为bash

I read here for date formats Convert date formats in bash

推荐答案

这应该可以解决问题

date -j -f '%d %b %Y' '+%A' '13 JAN 1995'

MacOS带有BSD日期,但是您的命令旨在与GNU日期一起使用.
看看 BSD strftime(3),然后再修改格式.

MacOS comes with BSD date, but your command is designed to work with GNU date.
Take a look at BSD strftime(3) before fiddling with the format.

这篇关于无法在bash mac中格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆