Java's SimpleDateFormat class

Source: Internet
Author: User


SimpleDateFormat


Date--Text

Date now = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); String strdate = Sdf.format (now); System.out.println (strdate);
Date now = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("yyyy mm month DD day"); String strdate = Sdf.format (now); System.out.println (strdate);
Date now = new Date (); SimpleDateFormat SDF = new SimpleDateFormat ("yyyy mm month DD Day HH:mm:ss"); String strdate = Sdf.format (now); System.out.println (strdate);


Text-to-date

Parse from a string into a Date object

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd"); try{Date date = Sdf.parse ("2018-10-10"); SYSTEM.OUT.PRINTLN (date);} catch (ParseException e) {System.out.println ("Time resolved error:" + e.getmessage ());}



Method

String Format (date date)

Format date as a string formats a date into a date/time string.

Date Parse (String source)

Parse String to date

Parses text from the beginning of the given string to produce a date.


650) this.width=650; "src=" Http://s2.51cto.com/wyfs02/M00/86/B7/wKiom1fIJxLySxqqAADe9c5j-t4156.png "title=" Date.png "alt=" Wkiom1fijxlysxqqaade9c5j-t4156.png "/>


Java's SimpleDateFormat class

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.