Java entry and faq _ 1 (3)

Source: Internet
Author: User
Tags date now dateformat
9. Display and format the date
Example:
Import java. util .*;
Import java. text .*;
Public class FormatDate {
Public static void main (String [] args ){
Date now = new Date ();
DateFormat defaultFormat = DateFormat. getDateInstance ();
DateFormat formatted format = DateFormat. getDateInstance (DateFormat. SHORT );
DateFormat mediumFormat = DateFormat. getDateInstance (DateFormat. MEDIUM );
DateFormat longFormat = DateFormat. getDateInstance (DateFormat. LONG );
DateFormat fullFormat = DateFormat. getDateInstance (DateFormat. FULL );
String defaultDate = defaultFormat. format (now );
String Updated Date = formatted format. format (now );
String mediumDate = mediumFormat. format (now );
String longDate = longFormat. format (now );
String fullDate = fullFormat. format (now );
System. out. println ("(Default) Today:" + defaultDate );
System. out. println ("(SHORT) Today:" + latest date );
System. out. println ("(MEDIUM) Today:" + mediumDate );
System. out. println ("(LONG) Today:" + longDate );
System. out. println ("(FULL) Today:" + fullDate );
}
}
The running result is:
D: javamail> java FormatDate
(Default) Today: 2003-6-15
(SHORT) Today: 03-6-15
(MEDIUM) Today: 2003-6-15
(LONG) Today: January 1, June 15, 2003
(FULL) Today: Sunday, January 1, June 15, 2003
10 What is the difference between static and non-static nested classes?
Static internal class meaning:
1. Create a static internal class object without an external class object
2. You cannot access an external class object from an object of a static internal class.
11. How can I determine whether the input is a character or a number?
Use Float. parseFloat (String data) to parse it
If NumberFormatException is thrown, it is not a number.
If you use StreamTokenizer, there is StreamTokenizer. ttype in it to determine whether it is a number.
You can also use Character. isDigit (char ch) to determine whether a Character is a number.
Character class method
Static boolean isDigit (char ch)
Determines if the specified character is a digit.
Static boolean isLetter (char ch)
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.