【发布时间】:2017-12-07 05:41:29
【问题描述】:
我想将字符串转换为时间戳。这是示例代码。
I want to parse the string to Timestamp..
我尝试将它转换为 字符串日期格式为“18/01/11”;
String date = "25/07/2017";
Timestamp ts =Timestamp.valueOf(date);
DateUtil.convertDate(ts.toString());
转换日期:-
SimpleDateFormat inputFormat = new SimpleDateFormat(
"yyyy-MM-dd HH:mm:ss");
Date d = null;
try {
d = inputFormat.parse(input);
} catch (ParseException e) {
System.out.println("Date Format Not Supported");
e.printStackTrace();
}
SimpleDateFormat outputFormat = new SimpleDateFormat("dd/MM/yyyy");
return outputFormat.format(d).toString();
如果我这样写,我会收到以下错误
Date Format Not Supported
Timestamp format must be yyyy-mm-dd hh:mm:ss[.fffffffff]
【问题讨论】:
-
你能写下实际的字符串吗?而且没有示例代码!
-
您是否考虑过使用
SimpleDateFormat将String解析为Date值?18/01/11与yyyy-mm-dd不一样 -
答案在这里你可以检查它是否有效here
-
请找到我的编辑.. 我添加了一些示例内容