Java format date to string or string to Date__java

Source: Internet
Author: User
Tags dateformat java format

Reference class: java.text
Class DateFormat

Java.lang.Object
  java.text.Format
      java.text.DateFormat
all implemented interfaces:Serializable, cloneable child classes are directly known:SimpleDateFormat

Construction Method Summary
Protected DateFormat ()
Create a new DateFormat.

Letters date or time element represents Sample
G Era Marker Text AD
Y Years Year 1996; 96
M Months of the year Month July; June June; 07
W Number of weeks in the year Number 27
W Number of weeks in the month Number 2
D Days in the year Number 189
D Days in the month Number 10
F Weeks in the month Number 2
E Days in the week Text Tuesday; Tue
A AM/PM Mark Text Pm
H Number of hours in a day (0-23) Number 0
K Number of hours in a day (1-24) Number 24
K Number of hours in am/pm (0-11) Number 0
H Number of hours in am/pm (1-12) Number 12
M Number of minutes in the hour Number 30
S Number of seconds in minutes Number 55
S Number of milliseconds Number 978
Z Time General Time Zone Pacific Standard time; PST; gmt-08:00
Z Time RFC 822 Time Zone -0800

date and time patterns Results
"YYYY. Mm.dd G ' at ' HH:mm:ss z ' 2001.07.04 AD at 12:08:56 PDT
"EEE, MMM D, ' yy" Wed, April 4, ' 01
"H:mm a" 12:08 PM
"HH ' o ' clock ' A, zzzz" O ' clock PM, Pacific Daylight Time
"K:mm A, z" 0:08 PM, PDT
"Yyyyy. MMMMM.DD GGG hh:mm AAA " 02001.july.04 AD 12:08 PM
"EEE, D MMM yyyy HH:mm:ss Z" Wed, 4 June 2001 12:08:56-0700
"Yymmddhhmmssz" 010704120856-0700
"Yyyy-mm-dd ' T ' HH:mm:ss." Sssz " 2001-07-04t12:08:56.235-0700

String format (date date)
Formats a date/time string.

Date Parse (String Source)
Parse the text from the beginning of the given string to generate a date
public static void Main (string[] args) throws parseexception ... {

The string convert to date according the format string
Date date = new Date ();
SimpleDateFormat strtodate = new SimpleDateFormat ("Yyyy-mm-dd-hh:mm:ss");
Parse format String to date
Date = Strtodate.parse ("2000-12-11-06:23:12");
SYSTEM.OUT.PRINTLN (date);

The date convert to format string according the format string
SimpleDateFormat datetostr = new SimpleDateFormat ("Dd/mm/yyyy-hh:mm:ss");
Parse date to format String
String temp = Datetostr.format (date);
SYSTEM.OUT.PRINTLN (temp);

}

Mon Dec 06:23:12 GMT 2000
11/12/2000-06:23:12

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.