Shell script to get the formatting Date and Time Summary
The Shell script obtains the formatting Date and Time summary. The Linux bash script's support for time formats exceeds my expectation and supports changes and outputs in multiple formats. It is even more convenient than java APIs. It is summarized as follows:
#! /Bin/sh # upload logs to hdfssource/etc/profile # obtain yesterday's date in the yyyyMMdd format yesterday = 'date -- date = '1 days ago '+ % Y % m % d '# obtain the format of yesterday's yyyy-MM-dd yesterday2 = 'date -- date = '1 days ago '+ % Y-% m-% d' # obtain today's date in the yyyyMMdd format today =' date -- date = '0 days ago '+ % Y % m % d' # Get today's date in yyyy-MM-dd format today2 = 'date -- date = '0 days ago' + % Y-% m-% d' # get tomorrow's date in yyyyMMdd format today = 'date -- date = '1 days '+ % Y % m % d' # get tomorrow's date in yyyy- MM-dd format today2 = 'date -- date = '1 days' + % Y-% m-% d' # obtain the current time yyyy-MM-dd HH: mm: ss format nowtime = 'date -- date = '0 days ago '"+ % Y-% m-% d % H: % M: % S "'# obtain the current daytime HH: mm: ss format nowtime2 = 'date -- date = '0 days ago' + % H: % M: % s' # obtain the time from yyyy-MM-dd HH: mm: ss format: onehourage = 'date -- date = '1 hours ago '"+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: ss format: onehourage2 = 'date -- date = '1 hours' "+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: 2 hours ago: ss format: twohourage = 'date -- date = '2 hours ago '"+ % Y-% m-% d % H: % M: % S "'# Get 2 hours later in yyyy-MM-dd HH: mm: ss format: twohourage2 = 'date -- date = '2 hours' "+ % Y-% m-% d % H: % M: % S "'# obtain yyyy-MM-dd HH: mm: 1 month ago: ss format date -- date = '1 month ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day before yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago + 1 day ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month minus 1 day before yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago-1 day ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day plus 1 hour plus 1 minute plus 1 second before the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month ago + 1 day ago + 1 hour ago + 1 min ago + 1 sec ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second before the time yyyy-MM-dd HH: mm: ss format can be +-misuse date -- date = '1 month ago + 1 day ago-1 hour ago-1 min ago-1 sec ago '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day plus 1 hour plus 1 minute plus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month + 1 day + 1 hour + 1 min + 1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 year after 1 month plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 year 1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S "# Get 1 month a year ago plus 1 day minus 1 hour minus 1 minute minus 1 second after the time yyyy-MM-dd HH: mm: ss format date -- date = '1 year 1 month + 1 day-1 hour-1 min-1 sec '"+ % Y-% m-% d % H: % M: % S"