Java implementation information based on the current date

xiaoxiao2021-03-31  214

/ ** * Get the current date of the day before yesterday, and information * @param nowDay's format: 2006-06-17 * / public static Properties getYesterdayAndtheDayOfYesterday (String nowDate) {Properties prop = new Properties (); try {String yesterday = getLastDayInfo ( nowDate); String theDayOfYesterday = getLastDayInfo (yesterday); prop.setProperty ( "yesterday", yesterday); prop.setProperty ( "theDayOfYesterday", theDayOfYesterday);} catch (Exception e) {e.printStackTrace ();} return prop; } / ** * Get the previous day information * @Param nowDate Format: 2006-06-17 * @Return * / public static string getlastdayinfo (string yesterday) {string yesterday = "; int year = 0; int Month = 0 INT day = 0; try {system.out.println ("0000000nowdate =" nowdate); // 2006-06-17 Year = integer.parstring (0, nowDate.indexof (")) ); Month = integer.parseint (nowDate.substring (nowDate.indexof ("-") 1, nowdate.lastIndexof ("-"))); day = integer.parseint (nowDate.substring Date.lastIndexof ("-") 1); system.out.println ("nowyear =" year); system.out.println ("nowMonth =" month; system.out.println ("dayday = " day);

Day = day - 1; if (day == 0) {MONTH = MONTH - 1; if (Month == 0) {// january month = 12; day = 31; Year = year - 1;} else {//// NOT JAN. Switch (Month) {// 1 | 3 | 5 | 7 | 8 | 10 | 12) Day = 31; Case 1: day = 31; Break; Case 3: day = 31; Break; Case 5: Day = 31; Break; Case 7: day = 31; Break; Case 8: day = 31; Break; Case 10: day = 31; Break; Case 12: day = 31; Break; // 4 | 6 | 9 | 11) Day = 30; Case 4: day = 30; Break; Case 6: day = 30; Break; Case 9: day = 30; Break; Case 11: Day = 30; Break; Case 2: IF (Year% 4 == 0 && Year% 100! = 0 || Year% 400 == 0) {// Leap Year Day = 29;} else day = 28;}}} String monthstr = ""; string daystr = ""; if (Month <10) {MONTHSTR = "0" String.Valueof (Month);} else {MONTHSTR = String.Valueof (Month);} IF (day <10 ) {DayStr = "0" string.valueof (day);} else {daystr =

转载请注明原文地址:https://www.9cbs.com/read-131024.html

New Post(0)