how to convert datetime to timestamp in java

前端 未结 5 1980
萌比男神i
萌比男神i 2021-01-22 21:24

forum member

I am having one problem with date time in java. Actually I am receiving the startdate in format 2012-02-27T01:10:10 and I want to insert th

相关标签:
5条回答
  • 2021-01-22 21:57

    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.

    0 讨论(0)
  • 2021-01-22 22:01

    Try this,

    yyyy-MM-dd'T'HH:mm:ss
    
    0 讨论(0)
  • 2021-01-22 22:04

    you can try like this....

    DateFormat format = new SimpleDateFormat("MMddyyHHmmss");
    Date date = format.parse("022310141505");
    
    0 讨论(0)
  • 2021-01-22 22:12

    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);
    
    0 讨论(0)
  • 2021-01-22 22:18
    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());
    
    0 讨论(0)
提交回复
热议问题