import java.text.SimpleDateFormat;
import java.util.Calendar;
public class Try {
  public static void main(String[]args)
  {
    SimpleDateFormat sdf=new SimpleDateFormat("EEE MM dd hh:mm:ss 'CST' yyyy");
    Calendar c=Calendar.getInstance();
    String time=null;
    time=sdf.format(c.getTime());
    System.out.println(time);
  }
}

解决方案 »

  1.   

    为什么我的sleep后的时间和前面的时间相同呢?import java.util.*;
    import java.text.SimpleDateFormat;
    import java.util.Calendar;public class MyThread extends Thread{
      public MyThread(String str) {
        super(str);
      }
      public void run(){
        SimpleDateFormat sdf=new SimpleDateFormat("EEE MM dd hh:mm:ss 'CST' yyyy");
        Calendar c=Calendar.getInstance();
        String time = null;
        time = sdf.format(c.getTime());
        for (int i = 0; i < 2; i++) {
          System.out.println(getName() + ": " + time);
          try {
            sleep(2000);
          } catch (InterruptedException e) {}
        }
        System.out.println("DONE! " + getName());
      }
      public static void main (String[] args) {
        for(int i = 0; i< 5; i++){
          new MyThread("Thread " + i).start();
        }
      }
    }