2016-09-20 15 views
-2

次のように に記載されているように、秒(分)、分(時)、時(分)、日(日)日付を&に変換する現在の日付時刻から所定の時刻を差し引いた時刻。 DATE1- DATE2 = DIFF、DATE1とDIFFを指定してDATE2を計算します。2つの日付時間の差から別の時刻を取得する

Means if current time is 2016-04-02T12:00:00 and given input is 23H60M then output should be 2016-04-01T12:00:00, and it can be 23D24H,can be 23M20S... 
400d - Only days (d) displayed 

20d23h - days (d) and hours (h) displayed 

14h33m - hours (h) and minutes (m) displayed 

10m59s - minutes (m) and seconds (s) displayed 
+4

これはコード作成サービスではありません。特に、あなたの質問が宿題のように見えるときは。 – Phylogenesis

答えて

1

このようなものを試すことができます。

#!/bin/bash 
input=$(echo $1 | tr '[:lower:]' '[:upper:]') 

if [[ $input == *"D"* ]] 
then 
input=$(echo $input | sed 's/D/ days ago /g') 
fi 

if [[ $input == *"H"* ]] 
then 
input=$(echo $input | sed 's/H/ hours ago /g') 
fi 

if [[ $input == *"M"* ]] 
then 
input=$(echo $input | sed 's/M/ minutes ago /g') 
fi 

if [[ $input == *"S"* ]] 
then 
input=$(echo $input | sed 's/S/ seconds ago /g') 
fi 
echo $input 


CURRENTDATE="$(date +%Y-%m-%d-%H:%M:%S)" 
echo $CURRENTDATE 
OLDERDATE="$(date "+%Y-%m-%d-%H:%M:%S" -d "$input")" 
echo $OLDERDATE 
関連する問題