How to get past 30 mins time in Solaris?

Hi guys,

could you help to find a way to get the past 30 mins time in solaris.

version:

bash-3.00# uname -a
SunOS solaris 5.10 Generic_142910-17 i86pc i386 i86pc

I had tried the following ways, it works fine in GNU Linux, but doesn't work in Solaris.

[root@book ~]# date
Tue Apr  2 01:01:49 CST 2013
[root@book ~]# date --date="-30 minutes"
Tue Apr  2 00:32:02 CST 2013
[root@book ~]# date -d '-30 minutes'
Tue Apr  2 00:32:27 CST 2013

thanks!

Look at the clock command, it requires TCL 8.5 or of course perl.

See

Or install GNU date.

Hi blackrageous,

if we use perl, how to write this command? I am not familiar perl :frowning:

Thanks!

---------- Post updated at 09:43 PM ---------- Previous update was at 08:40 PM ----------

I find the perl way to implement this requirement.

#!/usr/bin/perl

$now=localtime(time());
$then=localtime(time()-1800);

print "now is $now\n";
print "then is $then\n";

Thanks for your help!

localtime() has actually two representations, array and scalar.
By assigning it to a $variable the scalar representation is forced.
Certain functions like print can handle both representations, so a cast to scalar is necessary:

perl -le 'print scalar localtime(time-1800)'