相当于从日期GNU于Solaris [英] equivalent date from GNU to solaris

查看:109
本文介绍了相当于从日期GNU于Solaris的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

GNU 通过命令日期,我可以做到这一点:

In GNU with the command date I can do it:

date -d "+4 day"


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

但我想知道的:

我怎么能做到这一点在Solaris中?

how can i do it in Solaris?

与date命令

推荐答案

的Tcl具有良好的自由形式的日期的扫描仪,如果你已经安装的Tcl(试行这tclsh的) 。一个shell函数:

Tcl has a good free-form date scanner, if you have Tcl installed (try which tclsh). A shell function:

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行动

In action on an ancient Solaris 8 box with bash 2.03 and tcl 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

这甚至处理夏令时转换:

This even handles daylight savings transitions:

$ 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

这篇关于相当于从日期GNU于Solaris的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆