2013-07-23 72 views
1

GNU用命令的日期,我可以做到這一點:相當於日期與Solaris

date -d "+4 day" 


datei=20130101 
i=5 
date -d "$datei +$i day" 

但我想知道:

我怎樣才能做到這一點在Solaris中?

與date命令

+0

根據Solaris版本以及本地管理員安裝了哪些軟件包,GNU日期可以在'/ usr/gnu/bin/date'中找到,或者在'/ usr/sfw/bin','/ opt/csw/bin /','/ usr/local/bin /'等。 – alanc

回答

3

的Tcl具有良好的自由形式的日期掃描儀,如果你已經安裝的Tcl(試行which tclsh)。一個shell函數:

tcldate() { 
    d=${1:-now} # the date string 
    f=${2:-%c} # the output format 
    echo "puts [clock format [clock scan {$d}] -format {$f}]" | tclsh 
} 

在使用bash 2.03和TCL在一個古老的Solaris 8盒行動8.3.3

$ tcldate 
Tue Jul 23 13:27:17 2013 
$ i=4 
$ tcldate "$i days" 
Sat Jul 27 13:27:34 2013 
$ tcldate "$i days" "%Y-%m-%d" 
2013-07-27 
$ tcldate "20130101 + $i days" "%Y-%m-%d" 
2013-01-05 

這甚至處理夏令時轉換:

$ tcldate "2014-03-09 00:30 + 1 hour" "%D %T %Z" 
03/09/14 01:30:00 EST 
$ tcldate "2014-03-09 00:30 + 2 hour" "%D %T %Z" 
03/09/14 03:30:00 EDT 
$ tcldate "2013-11-03 00:30 + 1 hour" "%D %T %Z" 
11/03/13 01:30:00 EDT 
$ tcldate "2013-11-03 00:30 + 2 hour" "%D %T %Z" 
11/03/13 01:30:00 EST 
+0

說我-bash:找不到命令tclsh:。 =( –

+0

我沒有tclsh。是否有其他方法? –

+0

這是什麼給你的:'perl -MDate :: Manip -e 1'給你嗎? –