Java Time related content learning (5) SimpleDateFormat Introduction

Source: Internet
Author: User
Tags constructor locale object object stringbuffer

Introduce SimpleDateFormat.

SimpleDateFormat Introduction

SimpleDateFormat is a tool that formats date and parses date strings. Its most common use is to format date in the specified format, and then we use the string that can be obtained after the date is formatted.

More strictly speaking, SimpleDateFormat is a specific class that formats and parses dates in a way that is relevant to the locale. It allows for formatting (date-> text), parsing (text-> date), and normalization.

The SimpleDateFormat constructor:

Constructor SimpleDateFormat () SimpleDateFormat (string pattern) SimpleDateFormat (string template, DateFormatSymbols value) SimpleDateFormat (String template, Locale Locale)//non-constructor void Applylocalizedpattern (Str ing template) void Applypattern (String template) Object clone () bool  Ean equals (object) stringbuffer format (date date, StringBuffer buffer,                             FieldPosition fieldpos) Attributedcharacteriterator Formattocharacteriterator (Object object) Date Get2digityearstart () DateFormatSymbols getdateformatsymbols () int ha Shcode () Date parse (string string, parseposition position) void SE                           T2digityearstart (date date) void Setdateformatsymbols (dateformatsymbols value) String TolocaliZedpattern () String Topattern () 

SimpleDateFormat Simple demonstration:

New Date object, Time is 2013-09-19

Date date = new Date (113,8,19);

Creates a new SimpleDateFormat object and sets the "format mode" for SDF

SimpleDateFormat SDF = new SimpleDateFormat ("Yyyy-mm-dd");

Formats date with SDF and returns a string.

String str = sdf.format (date);

SimpleDateFormat Related Format description

Date and time patterns

Date and time formats are specified by date and time pattern strings. In a date and time pattern string, the unnamed letters ' a ' to ' Z ' and ' a ' to ' Z ' are interpreted as pattern letters, which are used to represent a date or time string element. The text can be enclosed in single quotes (') to avoid interpretation. "" "represents single quotes. All other characters are not interpreted; they are simply copied to the output string when they are formatted, or they match the input string when parsing.

The following pattern letters are defined (all other characters ' a ' to ' Z ' and ' a ' to ' Z ' are preserved):

Related Article

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.