string : 2014-04-25 17:03:13
使用SimpleDateFormat足以格式化吗?否则我将转向任何新的API?
Date date = new Date(string); DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd"); out.println( dateFormat.format (date));
我的预期结果是(印度区域):
Date : 25-04-2014 Time : 05:03 PM
记住Date对象没有固有的格式,您需要两个DateFormat对象来产生想要的结果-一个要解析,另一个要格式化:
Date
DateFormat
String input = "2014-04-25 17:03:13"; DateFormat inputFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); DateFormat outputFormat = new SimpleDateFormat("'Date : 'dd-MM-yyyy\n'Time : 'KK:mm a"); System.out.println(outputFormat.format(inputFormat.parse(input)));
输出:
请注意,在格式中使用带引号的序列(例如)"'Date : '",它被视为格式模式中的文字。
"'Date : '"