Use the date command to convert the Basic time second to year, month, and day:
Command:
Date-d @ 1281161747
Be sure not to forget the symbol "@"
# Obtain the current time by date
# Date-d "-1 week" + % Y % m % d get last week date (day, month, year, hour)
# Date -- date = "-24 hour" + % Y % m % d same as above
Date_now = 'date + % s' shell script to assign variable values
% Output % symbol
% A the abbreviation of the week for the current domain (Sun .. SAT)
% A full weekly write of the current domain (Sunday... Saturday)
% B abbreviated month of the current domain (Jan .. dec)
% B full name of the current domain (January... December)
% C default time format of the current domain (Sat Nov 04 12:02:33 est 1989)
% C n Centennial [00-99]
% D two days (01 .. 31)
% D short time format (mm/DD/yy)
% E short format Day (1 .. 31)
% F file time format same as % Y-% m-% d
% H same as % B
% H hour in 24-hour format (00 .. 23)
% I 12 hour (01 .. 12)
% J the day of the year (001 .. 366)
% K hour in short format in 24-hour format (0 .. 23)
% L hour in 12-hour short format (1 .. 12)
% M double-digit month (01 .. 12)
% M double-digit minutes (00 .. 59)
% N line feed
% N 000000000 S (999999999)
% P indicates the upper afternoon of the current domain in upper case (blank in upper Locales)
% P upper-afternoon indication of the current domain in lower case (blank in lower Locales)
% R 12-hour time representation (hour: minute: Second, double-digit) time, 12-hour (HH: mm: ss [AP] m)
% R 24-hour time representation (hour: minute, double digit) time, 24-hour (HH: mm)
% S number of seconds from the basic time 00:00:00 to the current time (a GNU extension)
% S second (00 .. 60 );
% T horizontal Tab)
% T 24-hour format (HH: mm: SS)
% U indicates the week (from Monday to 7)
% U the week Sunday of the year starts (00 .. 53)
% V The week Monday of the year is the start (01 .. 53)
% W the day of the week starts on Sunday (0 .. 6)
% W the week Monday of the year is the start (00 .. 53)
% X local Date Format (mm/DD/yy)
% X local time format (% H: % m: % s)
% Y two years (00 .. 99)
% Y year (1970 ...)
Example: How many days does it take to write a shell script to calculate its birthday?
Read-P "input your birthday (yyyymmdd):" date1
M = 'date -- date = "$ date1" + % m' # Get the birthday month
D = 'date -- date = "$ date1" + % d' # Get The Birthday Day
Date_now = 'date + % s' # obtain the second value of the current time
Y = 'date + % y' # Get the year of the current time
Birth = 'date -- date = "$ y $ M $ D" + % s' # obtain the second value of this year's birthday date.
Internal = $ ($ birth-$ date_now) # Calculate the interval from today to birthday
If ["$ internal"-lt "0"]; then # determines if today's birthday has passed
Birth = 'date -- date = "$ ($ Y + 1) $ M $ D" + % s' # Get the second value of tomorrow's birthday date
Internal = $ ($ birth-$ date_now) # Calculate the interval from today to the next birthday
Fi
Echo "there is: $ (einternal/60/60/24) days." # output result. seconds are converted to days.
Author "eonbell"