How to format date and time

JAVA time format processing
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. Convert
String dateTime = MessageFormat.format("{0,date,yyyy-MM-dd-HH-mm:ss:ms}" through MessageFormat,
                                    new Object[] {
                                        new java.sql.Date(System.currentTimeMillis( ))
                                    });
Description: yyyy-MM-dd-HH-mm:ss:ms year yyyy month MM day dd time (uppercase is 24, lowercase is 12) minutes mm seconds ss subtle ms

2、修改数据库时用
queryDataSet.setDate("dateField", new java.sql.Date(new java.util.Date().getTime()));
queryDataSet.setDate("dateField", new java.sql.Date.valueOf("2005-05-03"));

3. Convert SimpleDateFormat through
SimpleDateFormat dateFm = new SimpleDateFormat("yyyy-MM-dd"); //Format the current system date
String dateTime = dateFm.format(new java.util.Date());

The Java language's Calendar, Date, and DateFormat form a basic but very important part of the Java standard. Dates are a critical part of business logic calculations. All developers should be able to calculate Future dates, customize the display format of dates, and parse text data into date objects

1. Concrete class (relative  
to abstract class) java.util.Date 2. Abstract class java.text.DateFormat and one of its concrete subclasses, java.text.SimpleDateFormat  
3. Abstract class java.util.Calendar and one of its subclasses Concrete subclass, java.util.GregorianCalendar  

Concrete classes can be instantiated, but abstract classes cannot. You must first implement a concrete subclass of the abstract class. 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324726231&siteId=291194637