用下面的表达式,
bb '(new java.util.Date)'
#inst "2020-07-18T14:35:16.663-00:00"我希望得到一个字符串,并将其稍微格式化为:
"2020-07-18 UTC 14:35:16"关于Babashka (bb),我希望得到最少的依赖。否则,我可以用clj时间等来达到目标.
或者,如果我正在编写脚本,那么应该使用OS的date实用程序吗?
发布于 2020-07-18 16:04:34
在babashka中,您可以使用java.time包:
(import 'java.time.format.DateTimeFormatter
'java.time.LocalDateTime)
(def date (LocalDateTime/now))
(def formatter (DateTimeFormatter/ofPattern "yyyy-MM-dd HH:mm:ss"))
(.format date formatter) ;;=> "2020-07-18 18:04:04"发布于 2020-07-18 20:45:02
为了编写shell脚本,我定义了自己的方便bash/zsh函数:
function iso-date() {
date "+%Y-%m-%d"
}
function iso-date-short() {
date "+%Y%m%d"
}
function iso-time() {
date "+%H:%M:%S"
}
function iso-time-short() {
date "+%H%M%S"
}
function iso-date-time() {
echo "$(iso-date)t$(iso-time)"
}
function iso-date-time-nice() {
echo "$(iso-date) $(iso-time)"
}
function iso-date-time-str() {
echo "$(iso-date-short)-$(iso-time-short)"
}取得的成果:
~/cool > iso-date
2020-07-18
~/cool > iso-date-short
20200718
~/cool > iso-time
13:40:50
~/cool > iso-time-short
134059
~/cool > iso-date-time
2020-07-18t13:41:05
~/cool > iso-date-time-nice
2020-07-18 13:41:10
~/cool > iso-date-time-str
20200718-134114虽然我真的很喜欢Babashka (和GraalVM在一般!)额外的安装步骤对于简单的东西来说是过分的。
看这个回购用于通用GraalVM演示和Clojure模板项目,然后您可以在任何时候“滚动您自己的”!
https://stackoverflow.com/questions/62969992
复制相似问题