Java Date Processing Summary

Source: Internet
Author: User
Tags dateformat

1.java.sql.date

The date format (Rs.getdate ()) taken out of the database is Java.sql.Date, which is a subclass of Java.util.Date. After querying the API, it is found that there are few available methods. Consists of only 4 constructs:

Date(long date)
Constructs an object with a given millisecond time value Date .

  void settime (long date)
            sets an existing Date object with the given millisecond time value.
  String toString ()
            format Date Escape form Yyyy-mm-dd date.
static  date valueOf (string s)
            converts a string of JDBC date-escaped form to a date value.

The ValueOf method in which s represents the "yyyy-mm-dd" form of the date of the String object, if not the format, then an error. The ToString method, by default, returns a date in the form of "YYYY-MM-DD".

2.java.util.date

The java.util.Date reaction is Universal Time (UTC). The common methods of date are:

Date (): Initializes the current time
Date(long date)
Allocates an Date object and initializes the object to represent the specified number of milliseconds since the standard base time, known as the epoch, or January 1, 1970 00:00:00 GMT.

void settime (long time)
            sets this date object to represent the point in time of January 1, 1970 00:00:00 GMT after the timestamp millisecond.
Strin G toString ( )
          
converts this Date object to the following form of String : Dow mon dd hh:mm:ss zzz yyyy where: Dow is one day of the week ( Sun, Mon, Tue, Wed, Thu, Fri, Sat ).

The ToString () method for date is detailed as follows:

Convert this Date object to the following form String :

Dow Mon dd hh:mm:ss zzz yyyy

which

      • Dow is one day of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat).
      • Mon is the month (Jan, Feb, Mar, APR, May, June, Jul, Mar, Sep, Oct, Nov, Dec).
      • DD is a day in January (from two) and is displayed as a decimal number.
      • The hh is the hour of the day , which is displayed as a two-digit decimal number.
      • mm is the minute of the hour (from + to) and is displayed as a two-digit decimal number.
      • The SS is the number of seconds in minutes ( up to two) and is displayed in decimal digits. (The reason here is 61 seconds is because for UTC, an extra second is seen about every one or two years, called a "leap second.") Leap seconds is always incremented as the last second of the day and always increases on December 31 or June 30. )
      • zzz is the timezone (and can reflect daylight saving time). The standard time zone abbreviation includes the time zone abbreviation that the method parse recognizes. If you do not provide time zone information, the zzz is empty, meaning that no characters are included at all.
      • The yyyy is a year and is displayed as a 4-bit decimal number.
3. Date formatting DateFormat and SimpleDateFormat

DateFormat is an abstract class, and the class that actually formats the date is SimpleDateFormat.

  Date and Time mode:

Date and time formats are specified by a date and time pattern string. In a date and time pattern string, the unquoted letters ‘A‘ to ‘Z‘ and ‘a‘ to ‘z‘ are interpreted as pattern letters, which are used to represent date or time string elements . text can be caused by using single quotation marks ( ) to avoid interpretation. "‘‘"represents a single quotation mark . All other characters are not interpreted; Simply copy them to the output string when they are formatted, or match the input string when parsing.

Here's an example:

1 simpledateformat sdf=new SimpleDateFormat ("Yyyy-mm-dd HH:mm:ss"); 2 System.out.println (Sdf.format (new  Date () )); 3 Date date=sdf.parse ("2015-01-29 9:20:20"); 4 System.out.println (date);

  

Java Date Processing Summary

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.