To all the brothers who just learn Java and often come to this edition

Source: Internet
Author: User
Tags dateformat
To all the brothers who just learn Java and often come to this edition
On the jar, often (note, is often, and is very often!) Encountered some not difficult problems, even on the same day there are many similar problems, I think as a moderator, I can not just to answer the question for everyone (let alone there are many problems I do not understand), but need to talk about how to learn Java problem. I do not want you to encounter any small problems, the first thought is to ask people, so it is difficult to improve!
Let's take these two days for example! is a question about how to format dates, and asks how to output a Date object as string in the format you want. It is also asked how to convert a string class in a given format to a Date object.
Yesterday I just added a post to the essence of the section, as follows:
"Chenm" was posted on 2001-5-8 14:57:29 in Java technology ↑:
/*
File:timeformat.java
*/
Import java.lang.*;
Import java.text.*;
Import java.util.*;
public class timeformat{
Public TimeFormat () {
}
static public String Getchineseformattime () {
SimpleDateFormat SDF = new SimpleDateFormat ("yyyy. Mm.dd HH:mm:ss ");
Return Sdf.format (New Date ());
}
static public String Getsimpleformattime () {
SimpleDateFormat SDF = new SimpleDateFormat ("Yyyymmddhhmm", locale.us);
Return Sdf.format (New Date ());
}
}
As long as you look carefully, a friend who wants to solve his own problem must see that this code, though simple, has already explained the conversion of date to string. SimpleDateFormat's bag is java.text.
What about the conversion from string to date?
To learn Java, there is no Java API on the machine! Just check the SimpleDateFormat class method and find two parse methods with the return value date (one of which is an inherited DateFormat Class), so is it difficult to convert?
Just answered a post, the question is: "I want to use the 2000-09-03 string to construct a date, how to write straightforward date (" 2000-09-03 ") seems not to Ah", in fact, I think this friend has come to the solution of the front, But did not find a way to continue to go on. The date class has no such method of construction at all!
But there are other methods in the date class, in fact, the date class has only one method of static long parse (string s) that takes string as a parameter, but the API says: deprecated. As of JDK version 1.1, replaced by Dateformat.parse (String s). Well, look at the Java.text.DateFormat class. Of course the parse method of the DateFormat class supports not a lot of date formats, but is it a subclass SimpleDateFormat? These are all at a glance in the API!
In other jars, often see a lot of friends in the discussion, China's project management, ... No, no, lack of team consciousness or something, at that time I am very sad, because I am not a project master, I only know the honest writing program. But today I am more sad, because I found my friends many times, not even study!
Do not have nothing to do to find a batch, it is not not to ask questions, but really hope that we can improve, as the layout of the description in the written!
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.