Java time format processing

Source: Internet
Author: User

Java time formatting
Date formatting
Import java. util. date;
Import java. Text. simpledateformat;
Class daytime
{
Public static void main (string ARGs [])
{
Date nowtime = new date ();
System. Out. println (nowtime );
Sim
Java time formatting
Date formatting
Import java. util. date;
Import java. Text. simpledateformat;
Class daytime
{
Public static void main (string ARGs [])
{
Date nowtime = new date ();
System. Out. println (nowtime );
Simpledateformat time = new simpledateformat ("YYYY mm dd hh mm SS ");
System. Out. println (time. Format (nowtime ));
}
}
 

1. Use messageformat to convert
String datetime = messageformat. Format ("{0, date, yyyy-mm-dd-hh-MM: SS: Ms }",
New object [] {
New java. SQL. Date (system. currenttimemillis ())
});
Note: yyyy-mm-dd-hh-MM: SS: Mm DD, yyyy, Ms (24 in uppercase and 12 in lowercase) min mm second SS subtle Ms

2. Used to modify a database
Querydataset. setdate ("datefield", new java. SQL. Date (New java. util. Date (). gettime ()));
Querydataset. setdate ("datefield", new java. SQL. Date. valueof ("5-05-05-03 "));

3. Convert using simpledateformat
Simpledateformat datefm = new simpledateformat ("yyyy-mm-dd"); // format the current system date
String datetime = datefm. Format (New java. util. Date ());

4. Specific discussion
The calendar, date, and dateformat of the Java language constitute a basic but important part of the java standard. date is a key part of business logic computing. all developers should be able to calculate the future date, customize the display format of the date, and parse the text data into a date object. we wrote two articles. This is the first one. We will learn about date, date format, Date Parsing, and date calculation.

We will discuss the following classes:
1. java. util. Date
2. abstract class java. Text. dateformat and a specific subclass of Java. Text. simpledateformat
3. abstract class java. util. calendar and a specific subclass of it, java. util. gregoriancalendar

A specific class can be instantiated, but the abstract class cannot. You must first implement a specific subclass of the abstract class.

The date class evolved from the Java Development Kit (JDK) 1.0. At that time, it only contained several methods for obtaining or setting each part of a date data, such as months, days, and years. these methods have been criticized and transferred to the calendar class. We will discuss them further in this article. this improvement aims to better process the international format of date data. just like in JDK 1.1, the date class is actually just a package class, which contains a long integer data, represented from GMT (Greenwich Mean Time) 1970, the number of milliseconds that occurred before or after 00:00:00, January 1, January 1.
 
This article from: Development Institute http://edu.codepub.com Source: http://edu.codepub.com/2010/0727/24591.php

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.