在MM中从MM / DD / YYYY到DD-MMM-YYYY

Java中是否有可用于将MM/DD/YYYY转换为DD-MMM-YYYY

例如: 05/01/199901-MAY-99

谢谢!

使用SimpleDateFormat解析日期,然后使用具有所需格式的SimpleDateFormat将其打印出来。

这是一些代码:

  SimpleDateFormat format1 = new SimpleDateFormat("MM/dd/yyyy"); SimpleDateFormat format2 = new SimpleDateFormat("dd-MMM-yy"); Date date = format1.parse("05/01/1999"); System.out.println(format2.format(date)); 

输出:

 01-May-99 

尝试这个,

 Date currDate = new Date(); DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy"); String strCurrDate = dateFormat.format(currDate); System.out.println("strCurrDate->"+strCurrDate); 

尝试这个

 SimpleDateFormat sdf = new SimpleDateFormat("dd/MM/yyyy"); // Set your date format String currentData = sdf.format(new Date()); Toast.makeText(getApplicationContext(), ""+currentData,Toast.LENGTH_SHORT ).show(); 

下面应该工作。

 SimpleDateFormat df = new SimpleDateFormat("dd-MMM-yyyy"); Date oldDate = df.parse(df.format(date)); //this date is your old date object 
 formatter = new SimpleDateFormat("dd-MMM-yy");