我用 Java 编写了以下函数。此函数通过执行查询返回当前时间戳。函数代码如下:
private String getTimeStamp(){
String timeStamp=null;
try{
String strQuery="select current_timestamp";
PreparedStatement pmtQuery=con.prepareStatement(strQuery);
ResultSet rsQuery=pmtQuery.executeQuery();
rsQuery.next();
timeStamp=rsQuery.getString(1);
JOptionPane.showMessageDialog(null, "Value of timeStamp : "+timeStamp);
}catch(SQLException e){
System.out.println("SQL Exception in the getTimeStamp()");
}
return timeStamp;
}
当我在 Windows 上使用此功能时,它提供了正确的输出并且工作正常。 前任。
如果在 widows 中执行上面的函数,它会像 ex 一样给出时间戳。 2011-06-01 17:05:03
但是当我在 Debina linux 中执行这个函数时,它给出了时间戳 2011-06-01 17:05:03.0
它附加.0 到时间戳
请指导我解决这个问题
1.why such different output comes on different system? 2.How to avoid this problem? 3.How to solve this problem?
我正在使用以下配置
window
windows 7, Mysql 数据库, Java 6
Linux
Debian Linux、Mysql 数据库、Java 6
谢谢!
最佳答案
使用这个
SELECT DATE_FORMAT(CURDATE(), '%d/%m/%Y %hh%mm%ss')
注意:
我想知道你为什么要查询获取当前日期
关于java - 查询在不同的操作系统上给出不同的输出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6200650/