java - 在java中将时间戳转换为日期

标签 java mysql web-services soap valueconverter

<分区>

这是我的数据库: enter image description here

这里我要查看查询current date+status=Q的信息,得到计数值。

这是我的代码:

public class TodayQ {
    public int data() {
         int count=0;
        Date date = new Date(timestamp);
DateFormat dateFormat = new SimpleDateFormat ("yyyy-MM-dd");
System.out.println( dateFormat.format (date));

        // count++;

        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection con = DriverManager.getConnection(
                    "jdbc:mysql://localhost:3306/pro", "root", "");

            PreparedStatement statement = con
                    .prepareStatement("select * from orders where status='Q' AND date=CURDATE()");
            ResultSet result = statement.executeQuery();
            while (result.next()) {
                // Do something with the row returned.
                count++; // if the first col is a count.
            }

        }

        catch (Exception exc) {
            System.out.println(exc.getMessage());
        }

        return count;
    }

}

这里我要编辑的日期是(yyyy-mm-dd)格式。现在我得到了输出。但我希望在我的数据库上使用时间戳。那么如何在 Java 中将时间戳转换为日期。如何在我的代码中使用该代码?

最佳答案

您可以使用 mysql 函数实现相同的目的。希望以下查询能为您提供所需的输出。

select * 
from orders
where status='Q' AND 
      date_format(from_unixtime(date),'%Y-%m-%d') = current_date;

关于java - 在java中将时间戳转换为日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11794648/

相关文章:

java - 通过Matlab和Java驱动程序从MongoDB(gridfs)读取数据

Java = 运算符

mysql - Heroku SSL 连接错误不支持的协议(protocol)

web-services - 将 restful 架构映射到 CRUD 功能

java - JSTL:在自定义标签中使用 scriptlet

java - 如何在没有字符串的情况下验证正文响应?

mysql - MySQL 回滚失败

php - PDO 中插入语句的正确使用方法

web-services - Symfony2 通过网络服务对用户进行身份验证

java - 在 Java 中使用 Contract-First 的 Web 服务周期