如何将 Shell 中的日期转换为以下格式?

How I can convert date to following format in Shell?

我将日期作为参数传递,需要将其转换为 shell 中给定的格式。

在此处粘贴示例代码

echo "20190101120001" | xargs date +"%Y%m%d%H%M%S" -u

这应该将输出显示为

Tue Jan 01 12:00:01 UTC 2019

试试这个:

#!/bin/bash
str="20190101120001"
date -d "${str:0:8} ${str:8:2}:${str:10:2}:${str:12:2}" -u