Java 如何使用ApacheDerby格式化日期?
我想很好地格式化从以下查询中收到的日期:Java 如何使用ApacheDerby格式化日期?,java,date,derby,Java,Date,Derby,我想很好地格式化从以下查询中收到的日期: SELECT recdate FROM myrecords; 实际上,我正在用日期模式搜索函数的格式, 如果简化了格式就更好了。如果不可能,我如何构建用于格式化的类 有点像: SELECT MyFormatter(recdate) FROM myrecords 看这里: 示例代码: public static void main(String[] args) { // Get the Date object that comes from
SELECT recdate FROM myrecords;
实际上,我正在用日期模式搜索函数的格式,
如果简化了格式就更好了。如果不可能,我如何构建用于格式化的类
有点像:
SELECT MyFormatter(recdate) FROM myrecords
看这里:
示例代码:
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() + "\"");
}
}
^^这个。不用说,您(OP)不使用ApacheDerby(或任何关系数据库系统)来格式化日期。您使用格式化程序。您使用Derby通过SQL提取数据,并使用格式化程序对日期数据进行处理,使其变得漂亮。