Java date format convert on Android

后端 未结 8 1537
感情败类
感情败类 2020-12-22 10:14

I have date String as below:

Fri, 19 Jul 2013 01:30:22 GMT
Thu, 12 Sep 2013 19:19:18 GMT

And I want to convert to below format:

相关标签:
8条回答
  • 2020-12-22 10:40

    You can try this

    DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    Date date = dateFormat.parse("Fri, 23 Aug 2013 01:10:35 GMT");
    String formattedString=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss").
                                                         format(date).toString();
    System.out.println(formattedString);
    
    0 讨论(0)
  • 2020-12-22 10:44

    Try

    String           dateStr = "Fri, 19 Jul 2013 01:30:22 GMT";
    SimpleDateFormat sdf     = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    Date             date    = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").parse(dateStr); 
    System.out.println(sdf.format(date));
    
    0 讨论(0)
  • 2020-12-22 10:50

    Try with "format" :

    SimpleDateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z");
    String date = "";
    try {
       date = dateFormat.format("Fri, 23 Aug 2013 01:10:35 GMT");
    } catch(Exception e){
       e.printStackTrace();
    }
    
    0 讨论(0)
  • 2020-12-22 10:56

    Use this code

    String dateString = "Fri, 19 Jul 2013 01:30:22 GMT";
    
        SimpleDateFormat simple = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date date;
        try {
            date = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z")
                    .parse(dateString);
            Log.e("result", "Date:" + simple.format(date));
    
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    
    0 讨论(0)
  • 2020-12-22 10:57

    try this

    String DateStr="Fri, 19 Jul 2013 01:30:22 GMT";
        SimpleDateFormat sim=new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
        Date d = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z").parse(DateStr); 
    System.out.println(sim.format(d));
    
    0 讨论(0)
  • 2020-12-22 11:00

    try this

    DateFormat dateFormat = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss Z", Locale.ENGLISH);
    

    your default language is probably not English and does not accept Fri and Aug

    0 讨论(0)
提交回复
热议问题