mysql查找当前时间 大于 字段 shijian 格式(yyyy-MM-dd hh:mm:ss) 20分钟 的信息
时间: 2024-04-12 08:28:36 浏览: 82
可以使用MySQL的DATE_SUB函数来实现这个需求。以下是一个示例查询语句:
```
SELECT * FROM your_table
WHERE shijian < DATE_SUB(NOW(), INTERVAL 20 MINUTE);
```
在这个查询中,`your_table`是你要查询的表名,`shijian`是表示时间的字段名。`NOW()`函数返回当前时间,`DATE_SUB(NOW(), INTERVAL 20 MINUTE)`表示当前时间减去20分钟。
你可以根据实际情况替换表名和字段名。这个查询将返回字段`shijian`的值小于当前时间减去20分钟的所有记录。
相关问题
excel怎么随机生成1985-01-01 00:00:00格式的shijian
在 Excel 中,可以使用以下公式随机生成1985-01-01 00:00:00格式的日期时间:
=DATE(1985,1,1)+TIME(RANDBETWEEN(0,23),RANDBETWEEN(0,59),RANDBETWEEN(0,59))
其中,DATE和TIME函数分别代表日期和时间,RANDBETWEEN函数用于生成随机数。这个公式将会生成类似于“1985-01-01 12:34:56”的日期时间格式,其中年月日固定为1985年1月1日,而时分秒则随机生成。你可以根据需要对公式中的文本和符号进行修改,以生成你需要的日期时间格式。
翻译代码:package com.action; import java.text.SimpleDateFormat; import java.util.Date; import java.util.List; import java.util.Map; import org.apache.struts2.ServletActionContext; import com.dao.TGonggaoDAO; import com.model.TAdmin; import com.model.TGonggao; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionSupport; public class gonggaoAction extends ActionSupport { private Integer id; private String biaoti; private String neirong; private String shijian; private String message; private String path; private TGonggaoDAO gonggaoDAO; public String gonggaoAdd() { TGonggao gonggao=new TGonggao(); gonggao.setBiaoti(biaoti); gonggao.setNeirong(neirong); gonggao.setShijian(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date())); gonggaoDAO.save(gonggao); this.setMessage("公告添加完毕"); this.setPath("gonggaoMana.action"); return "succeed"; } public String gonggaoMana() { List gonggaoList =gonggaoDAO.findAll(); Map request=(Map)ServletActionContext.getContext().get("request"); request.put("gonggaoList", gonggaoList); return ActionSupport.SUCCESS; } public String gonggaoDel() { TGonggao gonggao=gonggaoDAO.findById(id); gonggaoDAO.delete(gonggao); this.setMessage("公告删除完毕"); this.setPath("gonggaoMana.action"); return "succeed"; } public String gonggaoDetailHou() { TGonggao gonggao=gonggaoDAO.findById(id); Map request=(Map)ServletActionContext.getContext().get("request"); request.put("gonggao", gonggao); return ActionSupport.SUCCESS; } public String gonggaoAll() { List gonggaoList =gonggaoDAO.findAll(); Map request=(Map)ServletActionContext.getContext().get("request"); request.put("gonggaoList", gonggaoList); return ActionSupport.SUCCESS; } public String gonggaoDetailQian() { TGonggao gonggao=gonggaoDAO.findById(id); Map request=(Map)ServletActionContext.getContext().get("request"); request.put("gonggao", gonggao); return ActionSupport.SUCCESS; } public String getBiaoti() { return biaoti; } public void setBiaoti(String biaoti) { this.biaoti = biaoti; } public TGonggaoDAO getGonggaoDAO() { return gonggaoDAO; } public void setGonggaoDAO(TGonggaoDAO gonggaoDAO) { this.gonggaoDAO = gonggaoDAO; } public Integer getId() { return id; } public void setId(Integer id) { this.id = id; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public String getNeirong() { return neirong; } public void setNeirong(String neirong) { this.neirong = neirong; } public String getPath() { return path; } public void setPath(String path) { this.path = path; } public String getShijian() { return shijian; } public void setShijian(String shijian) { this.shijian = shijian; } }
这是一个 Java 的 Struts2 框架的 Action 类,包含了公告的增删改查等方法。具体代码如下:
```
package com.action;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.apache.struts2.ServletActionContext;
import com.dao.TGonggaoDAO;
import com.model.TAdmin;
import com.model.TGonggao;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class gonggaoAction extends ActionSupport {
private Integer id;
private String biaoti;
private String neirong;
private String shijian;
private String message;
private String path;
private TGonggaoDAO gonggaoDAO;
public String gonggaoAdd() {
TGonggao gonggao=new TGonggao();
gonggao.setBiaoti(biaoti);
gonggao.setNeirong(neirong);
gonggao.setShijian(new SimpleDateFormat("yyyy-MM-dd HH:mm").format(new Date()));
gonggaoDAO.save(gonggao);
this.setMessage("公告添加完毕");
this.setPath("gonggaoMana.action");
return "succeed";
}
public String gonggaoMana() {
List gonggaoList =gonggaoDAO.findAll();
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("gonggaoList", gonggaoList);
return ActionSupport.SUCCESS;
}
public String gonggaoDel() {
TGonggao gonggao=gonggaoDAO.findById(id);
gonggaoDAO.delete(gonggao);
this.setMessage("公告删除完毕");
this.setPath("gonggaoMana.action");
return "succeed";
}
public String gonggaoDetailHou() {
TGonggao gonggao=gonggaoDAO.findById(id);
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("gonggao", gonggao);
return ActionSupport.SUCCESS;
}
public String gonggaoAll() {
List gonggaoList =gonggaoDAO.findAll();
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("gonggaoList", gonggaoList);
return ActionSupport.SUCCESS;
}
public String gonggaoDetailQian() {
TGonggao gonggao=gonggaoDAO.findById(id);
Map request=(Map)ServletActionContext.getContext().get("request");
request.put("gonggao", gonggao);
return ActionSupport.SUCCESS;
}
public String getBiaoti() {
return biaoti;
}
public void setBiaoti(String biaoti) {
this.biaoti = biaoti;
}
public TGonggaoDAO getGonggaoDAO() {
return gonggaoDAO;
}
public void setGonggaoDAO(TGonggaoDAO gonggaoDAO) {
this.gonggaoDAO = gonggaoDAO;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public String getNeirong() {
return neirong;
}
public void setNeirong(String neirong) {
this.neirong = neirong;
}
public String getPath() {
return path;
}
public void setPath(String path) {
this.path = path;
}
public String getShijian() {
return shijian;
}
public void setShijian(String shijian) {
this.shijian = shijian;
}
}
```
阅读全文