String date into Epoch time

后端 未结 4 1924
闹比i
闹比i 2020-12-07 06:44

I am little bit confused in dates. I am currently working on the weather app and everything works fine .. I just wanna handle this type of format into my own desirable forma

4条回答
  •  伪装坚强ぢ
    2020-12-07 06:57

    You can use SimpleDate formatter to parse you date as string into epoch

            String input = "2017-09-10T18:35:00+05:00";
            SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
            try {
                Date date = sf.parse(input);
                long dateInEpochFormatInMilliSeconds = date.getTime();
                //if you want this in seconds then
                long dateInEpochFormatInSeconds = date.getTime()/1000L;
                //if you want to show only date month and year then
                 SimpleDateFormat sdf = new SimpleDateFormat("dd-MM-yyyy");
                 String date = sdf.format(dateInEpochFormatInMilliSeconds);
                 //This date String will contain the date in dd-MM-yyyy format
            } catch (ParseException| ArithmeticException e) {
                e.printStackTrace();
            }
    

提交回复
热议问题