2013-11-28 40 views
0

如何将yyyy-MM-dd hh:mm:ss格式转换成2013年11月20日。格式是否适合显示?带[20th]后缀的日期格式

谢谢。

+0

我发现的是补丁。像th,ed等数组,我必须追加。他们按日期。 – nil

+0

发布您迄今已尝试过的代码。 –

回答

0
long yourmilliseconds =System.currentTimeMillis(); 
          SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS",Locale.US); 
          GregorianCalendar calendar = new GregorianCalendar(TimeZone.getTimeZone("US/Central")); 
          calendar.setTimeInMillis(yourmilliseconds); 
           time1=sdf.format(calendar.getTime()); 

time1 = time1.substring(0, time1.indexOf(",")); 
0

试试这个:

DateFormat inputFormat = new DateFormat("yyyy-MM-dd hh:mm:ss"); 
DateFormat outputFormat = new DateFormat("MMMM, dd yyyy"); 

Date date = inputFormat.parse("2013-11-28 00:52:19"); 
System.out.println(outputFormat.format(date)); 

可以使用this document参考。

0

你可以做类似的事情。

SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); 
    Date date=df.parse("2013-11-20 12:00:00"); 
    df=new SimpleDateFormat("MMMM, dd'th' yyyy"); 
    System.out.println(df.format(date)); 

出把

November, 20th 2013 
1

(现在不记得了)你需要这个工具方法追加thnd,我没有写,我从什么地方复制到我的代码:

public class NumberUtils { 
    public static String ordinal(int i) { 
     String[] sufixes = new String[] { "th", "st", "nd", "rd", "th", "th", 
      "th", "th", "th", "th" }; 
     switch (i % 100) { 
     case 11: 
     case 12: 
     case 13: 
     return i + "th"; 
     default: 
      return i + sufixes[i % 10]; 
     } 
    } 
} 

将其与其他答案结合起来,以获得所需的结果。