How can I convert a date in YYYYMMDDHHMMSS format to epoch or unix time?

前端 未结 2 1929
迷失自我
迷失自我 2020-12-22 00:58

EDIT: I have edited my question to include more information, I have tried many ways to do this already, asking a question on StackOverflow is usually my last resort. Any hel

2条回答
  •  执念已碎
    2020-12-22 01:40

    I got the answer after quite a while of trying different ways. The solution was pretty simple - to parse the time to a string as toString() didn't work.

        Date date;
        SimpleDateFormat df = new SimpleDateFormat("yyyyMMddHHmmss");
    
        try {
            date = df.parse(String.valueOf(_time.getTime()));
        } catch (ParseException e) {
            throw new RuntimeException("Failed to parse date: ", e);
        }
    
        return date.getTime();
    

提交回复
热议问题