我想很好地格式化从查询中收到的日期:
SELECT recdate FROM myrecords;
实际上我正在搜索函数以使用日期模式进行漂亮的格式化, 如果 SimpleDateFormat 之类的更好。如果不可能,我该如何构建一个用于格式化的类 像这样:
SELECT MyFormatter(recdate) FROM myrecords
最佳答案
看这里:
DateFormat and SimpleDateFormat Examples
示例代码:
public static void main(String[] args)
{
// Get the Date object that comes from DerbyDB...
//Date derbyDate = YOUR DATE FIELD HERE
// Make a SimpleDateFormat for toString()'s output. This
// has short (text) date, a space, short (text) month, a space,
// 2-digit date, a space, hour (0-23), minute, second, a space,
// short timezone, a final space, and a long year.
SimpleDateFormat format = new SimpleDateFormat("EEE MMM dd HH:mm:ss zzz yyyy");
// See if we can parse the output of Date.toString()
try
{
Date parsed = format.parse(derbyDate.toString());
System.out.println(parsed.toString());
}
catch(ParseException pe)
{
System.out.println("ERROR: Cannot parse \"" + derbyDate.toString() + "\"");
}
}
关于java - 如何使用 Apache Derby 格式化日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2572568/