You should check if gdate
is not already installed under your release of Solaris (might be in /usr/gnu/bin/date
, /usr/sfw/bin/[g]date
, /usr/local/bin/[g]date
, /usr/csw/bin/[g]date
or just /usr/bin/gdate
depending on the version). If not, it should be easy to find a package containing GNU date and install it.
Anyway, here is a shell function that should just work under a stock Solaris release and that do what I believe you want:
f()
{
echo $1 | perl -MTime::Local -nle '
use POSIX 'strftime';
$op='$2'*3600;
$sec=timelocal(0,0,$4,$3,$2-1,$1) if /(\d{4})(\d{2})(\d{2})(\d{2})/;
$sec=$sec+$op;
print strftime "%Y%m%d%H\n", localtime($sec);'
}
$ f 2014010112 -24
2013123112