
我有一個產生祖魯時區的腳本。如何像這樣更改 shell /bash 腳本中的格式?
20140730000255 -> 2014-07-30
先感謝您
問候
答案1
嘗試這個:
#!/bin/bash
LongDateTime=$1;
if ["$LongDateTime" = ""]
then
LongDateTime=20140730000255;
fi
Year=${LongDateTime:0:4}
Month=${LongDateTime:4:2}
Day=${LongDateTime:6:2}
echo $LongDateTime
echo $Year
echo $Month
echo $Day
YMD="$Year-$Month-$Day"
echo $YMD
希望這可以幫助。