******字符串转化成日期的效率比日期转化成字符串的效率要高!!**********************
例如:String checkDate = df.format(new Date());
and requ_time > to_date('" + checkDate + " 00:00:00', 'yyyy-mm-dd hh24:mi:ss')
************************************************************************
这里需要特别说明的是:new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");这里一定要写成大写的HH,
这样才支持24小时制,如果写成小写的hh那就是12小时制了。这点要特别注意。
***********************************************************************
时间格式如下的:Fri Jun 25 22:54:30 CST 2010 ,就靠这种方式来解析。
public String TransformDateTime(String value){
SimpleDateFormat format = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
Locale locale = Locale.US;
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy",locale);
Date d;
String str = null;
try {
d = sdf.parse(value);
Calendar c = Calendar.getInstance();
c.setTime(d);
str = format.format(c.getTime());
} catch (ParseException e) {
e.printStackTrace();
}
return str;
}
2. 另外还有一种无法解析的时间:
java.text.ParseException:
Unparseable date: "2010-06-25 19:54:30.0"
正在找解决办法...
找到了,直接去截取:
String str = "2010-06-25 19:54:30.0";
str = str.substring(0, str.indexOf("."));
SimpleDateFormat sdf = new SimpleDateFormat( "yyyy-MM-dd HH:mm:ss");
sdf.parse(str);
分享到:
相关推荐
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); date.setTime(time); System.out.println(sdf.format(date)); 发现时间于想要的时间不符,请运行Time.reg文件
JavaScript实现的java.text.SimpleDateFormat。希望多多交流。
有关SimpleDateFormat的常用方法说明
java 使用SimpleDateFormat类获取系统的当前时间 java 使用SimpleDateFormat类获取系统的当前时间
日期操作。。。基础的SimpleDateFormat格式化日期!!操作!》初级学习代码
目录SimpleDateFormat诡异bug复现SimpleDateFormat诡异bug字符串日期转Date日期(parse)Date日期转String类型(format)SimpleDateFormat出现bug的原因如何解决SimpleDateFormat多线程安全问题局部变量使用...
高并发之-SimpleDateFormat类的线程安全问题和解决方案.docx
1.创建SimpleDateFormat对象,确定日期被格式化的格式 2.使用循环,在循环中调用Thread的sleep方法,让线程休眠1s后打印当前时间的字符串
深入理解Java:SimpleDateFormat安全的时间格式化
SimpleDateFormat使用详解。非常实用!!!!
由浅入深解析 SimpleDateFormat 由浅入深解析 SimpleDateFormat
NULL 博文链接:https://qinchaoyong.iteye.com/blog/543109
NULL 博文链接:https://chaoyi.iteye.com/blog/2082317
NULL 博文链接:https://flynndang.iteye.com/blog/711878
SimpleDateFormat里面对应格式化输出的模式字母
SimpleDateFormat线程不安全的5种解决方案.md
SimpleDateFormat线程不安全的5种解决方案.docx
关于SimpleDateFormat的非线程安全问题及其解决方案.docx
Java 实例 - 格式化时间SimpleDateFormat使用源代码-详细教程.zip