java中怎么把20140124103709转换成yyyy-MM-dd hh:mm:ss形式的日期啊?
答案:6 悬赏:70
解决时间 2021-03-02 21:21
- 提问者网友:℡她的他i☆
- 2021-03-02 01:35
java中怎么把20140124103709转换成yyyy-MM-dd hh:mm:ss形式的日期啊?
最佳答案
- 二级知识专家网友:寂寞的炫耀
- 2021-03-02 02:11
public String changeTime(String time,)throws Exception{
if(StringUtil.isNull(time)){
throw new Exception("The time must not be null or ''");
}
SimpleDateFormat oldFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = oldFormat.parse(time);
return newFormat.format(date);
}
if(StringUtil.isNull(time)){
throw new Exception("The time must not be null or ''");
}
SimpleDateFormat oldFormat = new SimpleDateFormat("yyyyMMddHHmmss");
SimpleDateFormat newFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
Date date = oldFormat.parse(time);
return newFormat.format(date);
}
全部回答
- 1楼网友:万千宠爱
- 2021-03-02 06:46
Date date = sdf1.parse(); //yyyyMMddHHmmss
sdf2.format(date)////yyyy-MM-dd HH:mm:ss
- 2楼网友:請叫我丶偏執狂
- 2021-03-02 06:16
String s = "20140124103709";
SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddhhmmss");
Date date = (Date) sdf1.parse(s);
SimpleDateFormat sdf2 = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
System.out.print(sdf2.format(date));
- 3楼网友:都不是誰的誰
- 2021-03-02 05:35
给你一段代码,使用它就可以实现
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String dateString = "20140124103709";
try {
Date date = df.parse(dateString);
System.out.println(df.format(date));
} catch (Exception ex) {
System.out.println(ex.getMessage());
}
}
- 4楼网友:闲懒诗人
- 2021-03-02 05:00
String sDateStr="20140124103709";
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmss");
try {
System.out.println(sdf.parse(sDateStr));
} catch (ParseException e) {
//做转化失败的操作
}
}应该这样就能满足你的要求了,不过要注意判断长度是否都是14位,以防转换出错
- 5楼网友:最后战士
- 2021-03-02 03:42
public static string datetostring(date time){
simpledateformat formatter;
formatter = new simpledateformat ("yyyy-mm-dd hh:mm:ss");
string ctime = formatter.format(time);
return ctime;
}
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯