有没有什么通用的方法?包括其它类型的String日期 以及通用的 Date to String?

解决方案 »

  1.   

    String ds="Wed Dec 12 10:29:00 CST 2001";
    DateFormat df = DateFormat.getDateInstance(); 
    try {
             Date d = df.parse(ds);
          }
          catch(ParseException e) {
             System.out.println("Unable to parse " + ds);
          }     DateFormat df = DateFormat.getDateTimeInstance();
          String s = df.format(d);
          System.out.println("day is " + s);
      

  2.   

    import java.util.*;
    import java.text.*;DateFormat df = DateFormat.getDateInstance(DateFormat.MEDIUM, 
    DateFormat.MEDIUM,
    Locale.CHINA);String myString = df.format( new Date() )
      

  3.   

    Date now_time=new Date();
    int year=now_time.getYear()+1900;
    int month=now_time.getMonth()+1;
    int  day=now_time.getDate();int hour=now_time.getHours();
    int minute=now_time.getMinutes();
    int second=now_time.getSeconds();
      

  4.   

    To caolyf(小草):
    你的方法会导致ParseException,
    报:
    java.text.ParseException: Unparseable date: "Wed Dec 12 10:29:00 CST 2001"
    at java.text.DateFormat.parse(DateFormat.java:331)怎么解决?
      

  5.   

    sorry!SimpleDateFormat formatter= new SimpleDateFormat ("yyyy-MM-dd k:mm:ss");
    try
    {
      Date d=formatter.parse("2001-12-12 10:29:00");
      DateFormat df = DateFormat.getDateTimeInstance(); 
      System.out.println(df.format(d));
    }
    catch (ParseException ex)
    {
      System.out.println("Unable to parse ");
      

  6.   

    http://java.sun.com/j2se/1.3/docs/api/java/text/SimpleDateFormat.html