Calendar cal = Calendar.getInstance();
System.out.println(cal.getTime().toLocaleString());
 我想得到本地时间的。。 但是这个程序打印出来却不是我电脑右下边显示的时间。。
 请问怎么回事?
   还有我如何才能得到电脑右下角显示的时间。

解决方案 »

  1.   

    SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
    System.out.println(sdf.format(new Date()));
      

  2.   

    时区选择应该是没有问题。 是北京,重庆的那个
       
      用
     SimpleDateFormat sdf = new SimpleDateFormat("HH:mm");
     System.out.println(sdf.format(new Date()));
     这样也是不是我得到的系统时间。
      
      

  3.   

    你的不会是web程序吧?如果是,那是服务器上的时间,如果不是web程序,那就怪了..........
      

  4.   


    public class PrintCurrentTime { /**
     * 将日期按指定格式转换成字符串
     * @param date
     * @param style
     * @return
     */
    private String dateToString(Date date,String style){
    SimpleDateFormat sdf = new SimpleDateFormat(style);
    if(date!=null){
    return sdf.format(date);
    }
    return null;
    }
    /**
     * @param args
     */
    public static void main(String[] args) {
    String DATE_STYLE_BASIC="yyyy-MM-dd HH:mm:ss";
    System.out.print(new PrintCurrentTime().dateToString(new Date(), DATE_STYLE_BASIC));
    }}
      

  5.   

    public static void main(String[] args) {
    Calendar cal = Calendar.getInstance();
    DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT);
    System.out.println(df.format(cal.getTime()));
    }
      

  6.   

      我得到系统时间:
      我用的方法 要设置 时区,在程序中设置。。   SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd", Locale.CHINESE);  
        formatter.setTimeZone(TimeZone.getTimeZone("GMT+8"));  
    Calendar cal = Calendar.getInstance();
    boolean makeTimeDiffOrNot = util.instanceTimeDiff(formatter.format(cal.getTime()));
    这样就可以了 要设置时区 
      谢谢大家。
      

  7.   

      还有我如何才能得到电脑右下角显示的时间。  我来回答 :
           你看一下右下角 是什么时间  然后负值到一个String 就得到啦  so easy
         
      

  8.   

     SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMdd", Locale.CHINESE);  
        formatter.setTimeZone(TimeZone.getTimeZone("GMT+8"));  
                Calendar cal = Calendar.getInstance();
                boolean makeTimeDiffOrNot = util.instanceTimeDiff(formatter.format(cal.getTime()));