Android Format date with time zone

前端 未结 8 1357
被撕碎了的回忆
被撕碎了的回忆 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);
    

提交回复
热议问题