数据库存的日期是 1239930718 为int型的,怎么转换成正常的日期如:2009-04-17!
因为数据的初始数据是用PHP添加的,但是PHP添加时将正常的日期转换为int值存放到数据的,现在我们得将这int型的日期转换为正常的日期!

解决方案 »

  1.   

    不知楼主说的转换是在什么环境里转化,给个在java里转化的例子:
    int i = 1239930718;
    long l = (long)i;
    Date date = new Date(l);
    System.out.println(date);
    输出:1970-01-15希望对楼主有点用
      

  2.   

    你先把你的int型数据转换成string 类型,在对这个string进行截取操作
    如20090427
    String date=String.valueof(20090427);
    String str=date.substring(0,3)+"-"+date.substring(4,5)+"-"+date.substring(6,7);
      

  3.   

    如果你想日期仍然是一个日期类型
    Date date=Date.valueof(str);
    象这些你完全可以自己去看看api文档轻松就搞定
      

  4.   

    int i = 1239930718; 
    long l = (long)i; 
    Date date = new Date(l); 
    System.out.println(date); 
    输出:1970-01-15 
      

  5.   

    如果你是之前把时间的后面给割去的话,那我这个方法应该可以帮你忙public static void do12(int time) {
    long longTime = (long) time * 1000;
    SimpleDateFormat formattime = new SimpleDateFormat("yyMMdd");
    System.out.println(formattime.format(longTime));
    }但是得到的只是日期,因为之前已经把后面的时间去掉了,
      

  6.   

    sorry,没有看清你的要求,这个是你要的public static void do12(int time) {
    long longTime = (long) time * 1000;
    SimpleDateFormat formattime = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(formattime.format(longTime));
    }
    public static void main(String[] args) {
    do12(1239930718);
    }//结果为:2009-04-17
      

  7.   

    一句话搞定
    System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(1239930718000l)));
      

  8.   

    匿名内部类-_-!!!
    System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(1239930718000l)));public static void do12(int time) {
    long longTime = (long) time * 1000;
    SimpleDateFormat formattime = new SimpleDateFormat("yyyy-MM-dd");
    System.out.println(formattime.format(longTime));
    }
    public static String do13(int time) {
    return new SimpleDateFormat("yyyy-MM-dd").format((long)time * 1000);
    }
    public static void main(String[] args) {
    do12(1239930718);
    System.out.println(do13(1239930718));
    }
      

  9.   

    import java.text.SimpleDateFormat;public class converttime {
    public static String convertTime(Object objectData) { 
        String returnValue = ""; 
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); 
        try { 
          returnValue = dateFormat.format(objectData).toString(); 
        } 
        catch (Exception e) { 
          returnValue = ""; 
        } 
        return returnValue; 
      } }希望有帮助
      

  10.   

    谢谢了,分数等明天我加分后给  rascalboy520 
      

  11.   

    java中格式化时间是这样做的!顶
      

  12.   

    在数据库中可以用 num_date('1239930718000l','yyyy-mm-dd')
    我在Oracle中试过可以的,别的就不知道了,希望可以有用。
      

  13.   

    java中格式化时间是这样做的!顶