50分,Java 转换日期问题,急!!!!!!!!!!!!!!!!!!!!!!!!! 数据库存的日期是 1239930718 为int型的,怎么转换成正常的日期如:2009-04-17!因为数据的初始数据是用PHP添加的,但是PHP添加时将正常的日期转换为int值存放到数据的,现在我们得将这int型的日期转换为正常的日期! 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不知楼主说的转换是在什么环境里转化,给个在java里转化的例子:int i = 1239930718;long l = (long)i;Date date = new Date(l);System.out.println(date);输出:1970-01-15希望对楼主有点用 你先把你的int型数据转换成string 类型,在对这个string进行截取操作如20090427String date=String.valueof(20090427);String str=date.substring(0,3)+"-"+date.substring(4,5)+"-"+date.substring(6,7); 如果你想日期仍然是一个日期类型Date date=Date.valueof(str);象这些你完全可以自己去看看api文档轻松就搞定 int i = 1239930718; long l = (long)i; Date date = new Date(l); System.out.println(date); 输出:1970-01-15 如果你是之前把时间的后面给割去的话,那我这个方法应该可以帮你忙public static void do12(int time) { long longTime = (long) time * 1000; SimpleDateFormat formattime = new SimpleDateFormat("yyMMdd"); System.out.println(formattime.format(longTime)); }但是得到的只是日期,因为之前已经把后面的时间去掉了, 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 一句话搞定System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(1239930718000l))); 匿名内部类-_-!!!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)); } 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; } }希望有帮助 谢谢了,分数等明天我加分后给 rascalboy520 java中格式化时间是这样做的!顶 在数据库中可以用 num_date('1239930718000l','yyyy-mm-dd')我在Oracle中试过可以的,别的就不知道了,希望可以有用。 java中格式化时间是这样做的!顶 新手struts helloworld出错 Struts现在用的多吗,谁能给推荐一本好的java web的书!!! 请教struts1中更前端数据 求帮助:mina 初学 客户端连接不上 无法获得session 对象 struts2.0 valueStack的简单演示代码 在线等! 图片无法显示 分辨率固定 麻烦的问题:在网页中调用C++写的API问题 各位老师,帮我看看我错在哪里了,谢谢! struts2.0中标签s:autocompleter默认值问题 用java实现文件下载的问题,帮帮忙
int i = 1239930718;
long l = (long)i;
Date date = new Date(l);
System.out.println(date);
输出:1970-01-15希望对楼主有点用
如20090427
String date=String.valueof(20090427);
String str=date.substring(0,3)+"-"+date.substring(4,5)+"-"+date.substring(6,7);
Date date=Date.valueof(str);
象这些你完全可以自己去看看api文档轻松就搞定
long l = (long)i;
Date date = new Date(l);
System.out.println(date);
输出:1970-01-15
long longTime = (long) time * 1000;
SimpleDateFormat formattime = new SimpleDateFormat("yyMMdd");
System.out.println(formattime.format(longTime));
}但是得到的只是日期,因为之前已经把后面的时间去掉了,
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
System.out.println(new SimpleDateFormat("yyyy-MM-dd").format(new Date(1239930718000l)));
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));
}
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;
} }希望有帮助
我在Oracle中试过可以的,别的就不知道了,希望可以有用。