Android Format date with time zone

前端 未结 8 1349
被撕碎了的回忆
被撕碎了的回忆 2020-12-10 13:05

I need to format the date into a specific string.

I used SimpleDateFormat class to format the date using the pattern \"yyyy-MM-dd\'T\'HH:m

相关标签:
8条回答
  • 2020-12-10 13:49

    Try this

    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ", Locale.ENGLISH);   
    
    System.out.println("formatted string: "+sdf.format(c.getTime()));
    
    String text = sdf.format(c.getTime());  
    String result = text.substring(0, 22) + ":" + text.substring(22);  
    System.out.println("result = " + result);
    
    0 讨论(0)
  • 2020-12-10 13:50

    Try this code

    Calendar c = Calendar.getInstance();
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss Z", Locale.ENGLISH);
    String s = sdf.format(c.getTime());
    String fDate = s.substring(0, s.length()-2) +":"+s.substring(s.length()-2, s.length());
    Log.e("check", "formatted string: "+fDate);
    
    0 讨论(0)
提交回复
热议问题