Convert string Date into timestamp in Android?

后端 未结 5 725
面向向阳花
面向向阳花 2020-12-01 12:03

I want to convert my date (which is in String format), e.g. 13-09-2011, into Timestamp. I used below code but I got the 2011-09-13 00:00:00.0 as a result. But I want Timest

5条回答
  •  南方客
    南方客 (楼主)
    2020-12-01 12:43

    String str_date=month+"-"+day+"-"+yr;
    DateFormat formatter = new SimpleDateFormat("MM-dd-yyyy");
    Date date = (Date)formatter.parse(str_date); 
    long output=date.getTime()/1000L;
    String str=Long.toString(output);
    long timestamp = Long.parseLong(str) * 1000;
    

提交回复
热议问题