如何使用此输入解析日期字符串2019-08-06 08:26:17

时间:2019-08-15 03:27:34

标签: android

我想解析日期,但这会发生:

不可解析的日期:“ 2019-08-06 08:26:17”(偏移量为0)

@SpringBootApplication
@ComponentScan(basePackages = {"com.techno.homes.search"})

public class SearchApplication {
private static final Logger log = 
LoggerFactory.getLogger(SearchApplication.class);

public static void main(String[] args) throws Exception{
    SpringApplication.run(SearchApplication.class, args);
    Settings settings = Settings.builder().put("cluster.name", "elasticsearch").build();
    Client client=new Config().client();
    System.out.println(client.toString());

} 

} 

2 个答案:

答案 0 :(得分:3)

尝试一下:

    SimpleDateFormat df2 = new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
    SimpleDateFormat df3 = new SimpleDateFormat("MMM dd,yyyy  hh:mm a");
    String eDate ="2019-08-06 08:26:17";
    Date eDDte;
    try {
        eDDte = df2.parse(eDate);
        System.out.println("Date: " + df3.format(eDDte));
    } catch(ParseException e){
        e.printStackTrace();
    }

答案 1 :(得分:0)

尝试一下:

try {
        String stringDate= " 2019-08-06 08:26:17";
        stringDate = ltrim(stringDate);
        stringDate = rtrim(stringDate);
        DateFormat format = new SimpleDateFormat("MMM dd,yyyy  hh:mm a");
        Date date = format.parse(stringDate);
        Log.d("datesssss", date.toString());
    } catch (ParseException e) {
        Log.d("datessssError", e.toString());
    }