Conversion of date strings in Java---Blog Park Lao Niu Big Lecture Hall

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.