How to subtract or add days or months to a date on Solaris?

落花浮王杯 提交于 2020-01-17 05:19:19

问题


Linux date has the -d feature which is missing in Solaris. So how can I go about subtracting or adding days or months to a date on Solaris.


回答1:


you still can do this with perl or python oneliners, e.g., substract one day from current date:

$ date
Thu May 14 15:31:49 MEST 2015
$ python -c "from datetime import datetime, timedelta; print (datetime.now() - timedelta(1)).strftime('%c');"
Wed May 13 15:31:58 2015



回答2:


What you need is GNU date for Solaris. (Linux uses GNU tools)

If you are using a recent version of Solaris (no my friend, Solaris 10 can no longer be considered a recent version of Solaris) then it is installed by default. Just use gdate command instead of date command.

This reply has more answers for you. Just follow the links in that reply for what to do on Solaris 10. You sysadmin may already have done this for you. Before you proceed: Have you checked if gdate is available on your system ?



来源:https://stackoverflow.com/questions/30231953/how-to-subtract-or-add-days-or-months-to-a-date-on-solaris

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!