how to convert datetime to timestamp in java

廉价感情. 提交于 2019-12-02 02:35:56

SimpleDateFormat's format() method doesn't return a Date type.

try this:

Date startDate = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss").parse(sDate);

Try this,

yyyy-MM-dd'T'HH:mm:ss
String sDate = jsonObject.get("StartDate").toString();
String eDate = jsonObject.get("EndDate").toString();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd"); 
Date startD = sdf.format(sDate);
Timestamp startTime = new Timestamp(startD.getTime());

Date endD = sdf.format(eDate);
Timestamp endTime = new Timestamp(endD.getTime());

Of course only the date is parsed, since the pattern you provided to the SimpleDateFormat constructor only contains the date part! Add the time part to it and it will parse the time too just fine.

you can try like this....

DateFormat format = new SimpleDateFormat("MMddyyHHmmss");
Date date = format.parse("022310141505");
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!