About conversion of dates: Refer to the code below---Blog Park Lao Niu da Lecture Hall
Code purpose: 1, mainly to convert the date type of the string to a date type
2. Calculate the date of N days.
3, the calculation results into a string.
Learn more about conversions between strings: http://www.blogjava.net/Werther/archive/2009/06/09/280954.html
Package Text;import Java.text.parseexception;import Java.text.simpledateformat;import java.util.Calendar;import Java.util.date;public class Text {public static void Main (string[] args) throws ParseException {
Blog Park Lao Niu da Lecture hall String datestr= "2013-01-01 15:05:05"; int weeks=2; int week=3; String K=gettime (datestr,weeks,week); System.out.println (k); } public static string GetTime (String Time,int weeks,int week) throws ParseException { SimpleDateFormat format = New SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); Date d = format.parse (time);//Convert to date type Calendar c = calendar.getinstance (); C.settime (d);//This is the time to get the current computer, you can also change to a random time C.add (Calendar.date, (weeks-1) *7+week-1);//days after the date return Format.format (C.gettime ());} }
Conversion of date strings in Java---Blog Park Lao Niu Big Lecture Hall