赞
踩
工作中遇到对毫秒的处理,涉及到从Excel中取时间值,然后通过Java保存到Oracle数据库。
现对其处理过程进行整理
一、Java中对毫秒时间的处理
Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss.SSSSSS");
String dateStr = sdf.format(date);
Format中用“SSS”来表示毫秒,几个S表示保留几位
二、Oracle对毫秒时间的处理
select to_timestamp('2017-04-18 17:06:31.681054', 'yyyy-MM-DD HH24:MI:SS.ff') from dual;
Oracle中使用“ff”来表示毫秒
select to_char(systimestamp, 'yyyy-MM-dd HH24:MI:SSxff') from dual;
to_date()方法不能取到毫秒值
timestamp到date的转换
select cast(to_timestamp('2017-04-18 17:06:31.681054', 'yyyy-MM-DD HH24:MI:SS.ff') as date) as mydate from dual;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。