In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-02 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Solaries how to use date to get the date of the previous day, I believe that many inexperienced people do not know what to do, so this paper summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
The method of obtaining Historical date under 1.Linux system
Get the previous day's date:
Date-d last-day +% Y%m%d
Get date 15 days ago:
Executing the date-d command of Linux under date +% Y%m%d-- date'15 days ago'2.solaries does not work with oracle@cwgsdb1:~$ date-d last-day +% Y%m%ddate: illegal option-- dusage: date [- u] mmddHHMM [[cc] yy] [.SS] date [- u] [+ format] date-a [-] sss [.fff]
Obviously not, but you can format the current date output
The date command under oracle@cwgsdb1:~$ date +% Y%m%d201810263.solaries gets the previous day's date oracle@cwgsdb1:~$ echo `TZ=$TZ date`Friday, October 26, 2018 09:29:57 PM CSToracle@cwgsdb1:~$ echo `TZ=$TZ+16 date`Friday, October 25, 2018 09:30:11 PM localtimeoracle@cwgsdb1:~$ dateFriday, October 26, 2018 09:31:00 PM CSToracle@cwgsdb1:~$ echo `TZ=$TZ+24 date`Friday, October 25, 2018 01:31:55 PM localtimeoracle@cwgsdb1:~$ echo `TZ=$TZ+40 date`Wednesday, October 24, 2018 09:31:59 PM localtimeoracle@cwgsdb1:~$ echo $TZlocaltime
The time zone in China is + 8, so the method to get the time n days ago is:
OldDate= `TZ = $TZ+X date +% Y% m% d`
Among them, X=24*n-8
However, for too long a time, such as 10 days ago, the result returned by this method is not correct:
Oracle@cwgsdb1:~$ echo `TZ=$TZ+232 date`Friday, October 26, 2018 01:34:00 PM GMT
After testing, this method can obtain the time in the previous week.
Oracle@cwgsdb1:~$ echo `TZ=$TZ+112 date`Sunday, October 21, 2018 09:35:08 PM localtimeoracle@cwgsdb1:~$ echo `TZ=$TZ+160 date`Friday, October 20, 2018 09:35:24 PM localtimeoracle@cwgsdb1:~$ echo `TZ=$TZ+160 date`Friday, October 19, 2018 09:35:47 PM localtimeoracle@cwgsdb1:~$ echo `TZ=$TZ+184 date`Friday, October 26, 2018 01:35:57 PM GMT4.solaries use the perl command to obtain the historical time oracle@cwgsdb1:~$ echo `perl-MPOSIX-le 'print strftime "% Y%m%d% H%M%S" Localtime (time-15*24*60*60) '`20181011 213937 oracle`cwgsdb1VR $echo `perl-MPOSIX-le' print strftime "% Y%m%d% H%M%S", localtime (time) '`20181026 213951oracleroomcwgsdb1VOV $echo `perl-MPOSIX-le' print strftime "% Y%m%d% H%M%S", localtime (time-30*24*60*60) '`20180926 214011oracleroomcwgsdb1ren $echo `perl-MPOSIX-le' print strftime "% Y%m%d% H%M%S" Localtime (time-40*24*60*60) '`20180916 214016
The principle of this method is to get the current time or the historical time of the previous N days by calling the strftime function and using the current time minus the number of seconds of N days.
After reading the above, have you mastered how to use date to get the date of the previous day in solaries? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.