Use of Date and SimpleDateFormat

Source: Internet
Author: User

1  PackageFengke.dateandsimpledateformat;2 3 Importjava.text.ParseException;4 ImportJava.text.SimpleDateFormat;5 Importjava.util.Date;6 /**7 * Date and use of SimpleDateFormat;8  * @authorFeng Ke9 * Content:Ten * creation of 1.date; One * 2.simpleDateFormat Usage: Format (); Parse ().  A  * -  */ -  Public classDateandsimpledateformat { the      -     StaticDate date=NewDate (); -  -      Public Static voidMain (string[] args) { +Date date2=NewDate (); -Date Date3 =NULL; +         //static methods can only call static variables A         //date format not used atSYSTEM.OUT.PRINTLN ("Not used date format:"); - System.out.println (date); -         //Set Date format -SimpleDateFormat simpledateformat=NewSimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); -         //formatting time, Format () method converts a date to text in the specified format -String date2_temp=Simpledateformat.format (date2); in         //Use date format -SYSTEM.OUT.PRINTLN ("Use date format (date---" String): "); to System.out.println (date2_temp); +         //convert text to a date using the parse () method -String time= "January 14, 2015 9:50:23"; the         //Parse () converts the text date to date *SimpleDateFormat simpledateformat2=NewSimpleDateFormat ("yyyy mm month DD Day HH:MM:SS"); $         Try {Panax Notoginsengdate3=Simpledateformat2.parse (time); -}Catch(ParseException e) { the             //TODO auto-generated Catch block + e.printstacktrace (); A         } theSYSTEM.OUT.PRINTLN ("Use date conversion format (String---" date): "); + System.out.println (date3); -          $  $     } -  -}

Use of Date and SimpleDateFormat

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.