1.
import java.util.Calendar;class test() {
public static void main(String[] arg) {
Calendar now = new Calendar.getInstance();
int iYear, iMonth, iDate;
String str = null;
iYear = now.YEAR;
iMonth = now.Month;
iDate = now.DAY_OF_MONTH;
str = iYear + "Äê" + iMonth + "ÔÂ" + iDate + "ÈÕ";
System.out.println(str);
}
}2.将java.sql.date转化成java.util.date

解决方案 »

  1.   

    import java.util.*;public class Now {public static void  main(String arg[]) {
        /* 
        ** on some JDK, the default TimeZone is wrong
        ** we must set the TimeZone manually!!!
        **   Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("EST"));
        */
        Calendar cal = Calendar.getInstance(TimeZone.getDefault());
        
        String DATE_FORMAT = "yyyy-MM-dd HH:mm:ss";
        java.text.SimpleDateFormat sdf = 
              new java.text.SimpleDateFormat(DATE_FORMAT);
        /*
        ** on some JDK, the default TimeZone is wrong
        ** we must set the TimeZone manually!!!
        **     sdf.setTimeZone(TimeZone.getTimeZone("EST"));
        */
        sdf.setTimeZone(TimeZone.getDefault());          
              
        System.out.println("Now : " + sdf.format(cal.getTime()));
        }
    }
     
    Here some formatting possibilities available through the SimpleDateFormat class.
    Thanks to T. Guirado for the tip. import java.util.*;
    import java.text.*;public class ShowToday {
      public static void main(String args[]) {
         ShowToday st = new ShowToday();
         st.demo();
         }
      public void demo() {   
         System.out.println(easyDateFormat("dd MMMMM yyyy"));
         System.out.println(easyDateFormat("yyyyMMdd"));
         System.out.println(easyDateFormat("dd.MM.yy"));
         System.out.println(easyDateFormat("MM月dd日yy年"));
         System.out.println(easyDateFormat("yyyy.MM.dd G 'at' hh:mm:ss z"));
         System.out.println(easyDateFormat("EEE, MMM d, ''yy"));
         System.out.println(easyDateFormat("h:mm a"));
         System.out.println(easyDateFormat("H:mm:ss:SSS"));
         System.out.println(easyDateFormat("K:mm a,z"));
         System.out.println(easyDateFormat("yyyy.MMMMM.dd GGG hh:mm aaa"));
         }  public String easyDateFormat (String format) {
        Date today = new Date();
        SimpleDateFormat formatter = new SimpleDateFormat(format);
        String datenewformat = formatter.format(today);
        return  datenewformat;
        }
      }
     
      

  2.   

    Sorry,出乱码了1.
    import java.util.Calendar;class test() {
        public static void main(String[] arg) {
            Calendar now = new Calendar.getInstance();
            int iYear, iMonth, iDate;
            String str = null;
            iYear = now.YEAR;
            iMonth = now.Month;
            iDate = now.DAY_OF_MONTH;
            str = iYear + "年" + iMonth + "月" + iDate + "日";
            System.out.println(str);
        }
    }2.将java.sql.date转化成java.util.date 
      

  3.   

    8.3.12 DATE, TIME, and TIMESTAMP
    There are three JDBC types relating to time: The JDBC DATE type represents a date consisting of day, month, and year. The corresponding SQL DATE type is defined in SQL-92, but it is implemented by only a subset of the major databases. Some databases offer alternative SQL types that support similar semantics. 
    The JDBC TIME type represents a time consisting of hours, minutes, and seconds. The corresponding SQL TIME type is defined in SQL-92, but it is implemented by only a subset of the major databases. As with DATE, some databases offer alternative SQL types that support similar semantics. 
    The JDBC TIMESTAMP type represents DATE plus TIME plus a nanosecond field. The corresponding SQL TIMESTAMP type is defined in SQL-92, but it is implemented by only a very small number of databases. 
    Because the standard Java class java.util.Date does not match any of these three JDBC date/time types exactly (it includes both DATE and TIME information but has no nanoseconds), JDBC defines three subclasses of java.util.Date to correspond to the SQL types. They are: java.sql.Date for SQL DATE information. The hour, minute, second, and millisecond fields of the java.util.Date base class should be set to zero. If the number of milliseconds supplied to the java.sql.Date constructor is negative, the driver will compute the date as the number of milliseconds before January 1, 1970. Otherwise, the date is computed as the specified number of milliseconds after January 1, 1970. java.sql.Time for SQL TIME information. The year, month, and day fields of the java.util.Date base class are set to 1970, January, and 1. This is the "zero" date in the Java epoch. 
    java.sql.Timestamp for SQL TIMESTAMP information. This class extends java.util.Date by adding a nanoseconds field. 
    All three of the JDBC time-related classes are subclasses of java.util.Date, and as such, they can be used where a java.util.Date is expected. For example, internationalization methods take a java.util.Date object as an argument, so they can be passed instances of any of the JDBC time-related classes. A JDBC Timestamp object has its parent's date and time components and also a separate nanoseconds component. If a java.sql.Timestamp object is used where a java.util.Date object is expected, the nanoseconds component is lost. However, since a java.util.Date object is stored with a precision of one millisecond, it is possible to maintain this degree of precision when converting a java.sql.Timestamp object to a java.util.Date object. This is done by converting the nanoseconds in the nanoseconds component to whole milliseconds (by dividing the number of nanoseconds by 1,000,000) and then adding the result to the java.util.Date object. Up to 999,999 nanoseconds may be lost in this conversion, but the resulting java.util.Date object will be accurate to within one millisecond. The following code fragment is an example of converting a java.sql.Timestamp object to a java.util.Date object that is accurate to within one millisecond. Timestamp t = new Timestamp(98724573287540L);
    java.util.Date d;
    d = new java.util.Date(t.getTime() + (t.getNanos() / 1000000));New methods in the JDBC 2.0 core API make it possible for the driver to take a specified time zone into account when calculating a date, time, or timestamp. The time zone information is included in a java.util.Calendar object that is passed to new versions of the methods for getting and setting Date, Time, and Timestamp values. When no time zone is specified, the driver uses the time zone of the virtual machine running the application when it calculates a date, time, or timestamp. 简单点就是:Date now=new Date();
    DateFormat df=DateFormat.getDateTimeInstance();
    String myString = df.format(now);
    out.println("myString="+myString);看看效果!
      

  4.   

    Timestamp lRtn = resultset.getTimestamp(index);SimpleDateFormat lFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    System.out.println(lFormatter.format(lRtn));
      

  5.   

    Timestamp lRtn = resultset.getTimestamp(index);SimpleDateFormat lFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    System.out.println(lFormatter.format(lRtn));
      

  6.   

    SimpleDateFormat lFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    System.out.println("Timestamp = [" + lFormatter.format(resultset.getTimestamp(index)) + "]");
      

  7.   

    SimpleDateFormat lFormatter = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    System.out.println("Timestamp = [" + lFormatter.format(resultset.getTimestamp(index)) + "]");