转换日期时间和QUOT; 2012年4月6日"格式日期、格式、时间、QUOT

2023-09-06 10:37:19 作者:recall with nostalgia(留恋)

我想这一天在第六届第七..等等。日期字符串。

我已经试过 SimpleDateFormater &放大器;还尝试与的DateFormatSymbols 。 (在code这个被提及我previous问题),但是我没有得到像定的String。

有没有其他的解决方案。

解决方案

  SimpleDateFormat的格式=新的SimpleDateFormat(D);
字符串日期= format.format(新日期());

如果(date.endsWith(1)及&安培;!date.endsWith(11))
    格式=新的SimpleDateFormat(EE MMM德圣',YYYY);
否则如果(date.endsWith(2)及&安培;!date.endsWith(12))
    格式=新的SimpleDateFormat(EE MMM德第二,YYYY);
否则如果(date.endsWith(3)及&安培;!date.endsWith(13))
    格式=新的SimpleDateFormat(EE MMM D'RD,YYYY);
其他
    格式=新的SimpleDateFormat(EE MMM德日,YYYY);

字符串yourDate = format.format(新日期());
 

试试这个, 这看起来像一些静态的,而是正常工作......

I want to get the day in "6th 7th.. etc." of the Date string.

excel中如何把2012.1.1日期格式改成2012 1 1这种格式

I have tried SimpleDateFormater & also try with DateFormatSymbols. (The code for this is mentioned in my previous question) but i m not getting like the given String.

Is there any other Solutions.

解决方案

SimpleDateFormat format = new SimpleDateFormat("d");
String date = format.format(new Date());

if(date.endsWith("1") && !date.endsWith("11"))
    format = new SimpleDateFormat("EE MMM d'st', yyyy");
else if(date.endsWith("2") && !date.endsWith("12"))
    format = new SimpleDateFormat("EE MMM d'nd', yyyy");
else if(date.endsWith("3") && !date.endsWith("13"))
    format = new SimpleDateFormat("EE MMM d'rd', yyyy");
else 
    format = new SimpleDateFormat("EE MMM d'th', yyyy");

String yourDate = format.format(new Date());

Try this, This looks like some static but works fine...