# 日期格式处理及求两个日期之间天数

`#!/bin/ksh############################################################################ Date calculations using Korn shell (ksh88)# Tapani Tarvainen July 1998, May 2000# This code is in the public domain.# Julian Day Number from calendar datedate2julian()   #  day month year{  typeset -i day month year tmpmonth tmpyear  day=\$1;  month=\$2;  year=\$3  ((tmpmonth = 12 * year + month - 3))  ((tmpyear = tmpmonth / 12))  print \$(( (734 * tmpmonth + 15) / 24 -  2 * tmpyear + \    tmpyear/4 - tmpyear/100 + tmpyear/400 + day + 1721119 ))}#### Matt's Added formatting#### Store input datesdate1=\$1date2=\$2# Get the dates into their respective fields.  Uncomment the format of# date input being used.# YYYYMMDDyear1=\${date1%????}; mmdd1=\${date1#????}; month1=\${mmdd1%??}; day1=\${mmdd1#??}year2=\${date2%????}; mmdd2=\${date2#????}; month2=\${mmdd2%??}; day2=\${mmdd2#??}# YYYY/MM/DD  or YYYY/M/D#print \$date1 |IFS=/ read year1 month1 day1#print \$date2 |IFS=/ read year2 month2 day2# MM/DD/YY    or M/D/YYYY#print \$date1 |IFS=/ read month1 year1 day1#print \$date2 |IFS=/ read month2 year2 day2# Calculate and print the difference between dates (date2 - date1)print -- "\$((\$(date2julian \$day2 \$month2 \$year2) - \$(date2julian \$day1 \\$month1 \$year1)))"`

• 博文量
133
• 访问量
429060