Java 带[20]后缀的日期格式

Java 带[20]后缀的日期格式,java,android,date,date-formatting,Java,Android,Date,Date Formatting,如何将yyyy-MM-dd hh:MM:ss格式转换为2013年11月20日。格式用于显示 谢谢。您可以使用 long yourmilliseconds =System.currentTimeMillis(); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss,SSS",Locale.US);

如何将yyyy-MM-dd hh:MM:ss格式转换为2013年11月20日。格式用于显示

谢谢。

您可以使用

    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(","));
像这样:

SimpleDateFormat sourceFormat = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss a");
SimpleDateFormat desiredFormat =new SimpleDateFormat("EEE,dd-MMM-yyyy");    
Date dt = sourceFormat.parse(your_date);
String desiredDateString = desiredFormat.format(dt)
试试这个:

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));

你可以参考。

你也可以做类似的事情

    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

您需要此实用程序方法来附加
th
nd
,我没有编写它,我从某个地方复制到我的代码中(现在不记得了):


将它与其他答案结合起来,以获得期望的结果。

我发现的是补丁。比如th,ed等的数组,我必须附加。按日期发布。发布您迄今为止尝试过的代码。
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];
        }
    }
}