public static String getDateString(String lDate) {
        String x = lDate.trim();
        String retStr = null;
        if (x == null || x == "") {
            x = "0";
        }
        if (x != "0") {
            x = x + "000";
            long idate = Long.parseLong(x);
            Date date = new Date(idate);
            DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT);
            retStr = df.format(date);
        } else {
            Date date = new Date();
            SimpleDateFormat formater = new SimpleDateFormat();
            formater.applyPattern("yyyy-M-dd");
            retStr = formater.format(date);
        }
        return retStr;
    }
System.out.println(getDateString("1252641537"));
在windows下是
2009-9-11
linux下就变成
Sep 11, 2009求解。。 

解决方案 »

  1.   

    跟你的Locale有关系吧 按照我的印象,你linux下面那种输出应该是Locale.English
      

  2.   

    你是要linux跟Windows的一样 是吗?
    其实SimpleDateFormat有一个构造方法,可以强制格式化成指定Locale的时间格式SimpleDateFormat(String pattern, Locale locale)
      

  3.   


    Date date = new Date(idate);
    DateFormat df = DateFormat.getDateInstance(DateFormat.DEFAULT);
    retStr = df.format(date);
    主要是这段代码
      

  4.   

    long idate = 1252641537000;
      

  5.   

    不好意思 没仔细看你的代码 你的代码是不是先把一个long型整数构造成一个Date变量 然后在格式化输出?你看看这个代码在你的两台机器上输出是不是一样的。public static void main (String[] args) { 
    long l = 1252641537000l; Date d = new Date(l);

    SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.CHINESE);

    System.out.println(format.format(d));