Time Formatting Exercises

Source: Internet
Author: User
Tags dateformat

1 /*2 1. Get the current time of the system3 2.date-->string4 3.string-->date5 */6 Importjava.util.Date;7 ImportJava.text.SimpleDateFormat;8 9  Public classTest02Ten { One      Public Static voidMain (string[] args)throwsexception{ A          -  -         //Get system Current time theDate Nowtime =NewDate (); -  -         //java.util.Date; class has overridden the ToString method -System.out.println (Nowtime);//Sun Dec 15:35:05 CST +          -         //================================================ +         //date-->string A         //formatted Date (a string that converts a date type to a specific format in a process) at  -         //1. Create date Format Object -SimpleDateFormat SDF =NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss SSS"); -         //SimpleDateFormat sdf = new SimpleDateFormat ("yyyy year MM-DD HH:mm:ss SSS"); -  -         //2. Formatting of the finish date of the calling format method inString Strnowtime =Sdf.format (nowtime); -  toSystem.out.println (Strnowtime);//2012-12-30 15:40:13 390 +  -         //========================================= the         //string-->date *         //1. Create date Format Object $SimpleDateFormat DateFormat =NewSimpleDateFormat ("Yyyy-mm-dd");Panax Notoginseng  -         //2. Given a date string theString time = "2008-08-08";//The format must be the same as the format specified in SimpleDateFormat.  +  A         //3. Call the Parse method theDate T =Dateformat.parse (time); +  -System.out.println (t);//Fri 00:00:00 CST $  $  -     } -};

Time Formatting Exercises

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.