Java随机数和日期相减


<%@ include file="../../inc/head.jsp"%>
<%@ page language="java"
import="java.sql.*,java.util.*,com.zj.comm.util.Common,com.zj.hz.bizq.WapSpecialNews,com.zj.hz.vo.*,com.zj.hz.util.*,java.text.*"
pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<wml>
<head>
<meta http-equiv="Cache-Control" content="max-age=0" />
<meta http-equiv="Cache-Control" content="no-cache" />
</head>
<card id="index1" title="<%=Common.getPropertiesValue("SITETITLE")%>">
<p>
<a href="./">首页</a>>>抢股<br/>
<%
// 得到当前用户和用户的登入时间
String mobile = Common.getMobile(request);
// java.util.Date now1= new java.util.Date();
// SimpleDateFormat f = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
// String nowtime = f.format(now);
Calendar cal=Calendar.getInstance();
SimpleDateFormat sf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
String nowtime=sf.format(cal.getTime());
// java.util.Date nowtime=f.parse(nowtime1);
//得到随机数
Random rand = new Random();
int ran = rand.nextInt(24);
//数据库连接
Connection conn = null;
PreparedStatement ps = null;
PreparedStatement pst = null;
PreparedStatement psi = null;
PreparedStatement psl = null;
PreparedStatement psm = null;
PreparedStatement psn = null;
PreparedStatement psq = null;
ResultSet rsm = null;
ResultSet rst = null;
ResultSet rsn = null;
ResultSet rsq = null;
try {
conn = DBClassLocal.getConnection();
String sqli = "select count(mobile) from hd_hotbuy where mobile='"+ mobile + "'";
pst = conn.prepareStatement(sqli);
rst = pst.executeQuery();
if (rst.next()) {
int num = rst.getInt(1);
if (num == 0) {
// LocalJDBCTemplate.insertData("insert into hd_spring (username,userphone,sign,mobile,person) values (?,?,?,?,?)",new Object[]{name,phone,"lake",mobile,person});
LocalJDBCTemplate.insertData("insert into hd_hotbuy (usertime,mobile) values (?,?)",new Object[]{nowtime,mobile});
try{
String sqq="select * from hd_hotbuy where random='"+ran+"'";
psq=conn.prepareStatement(sqq);
rsq=psq.executeQuery();
// out.println(rsq);
String aa="";
String stock="";
String point="";
if(rsq.next()){
stock = rsq.getString("rank");
point = rsq.getString("point");
aa="恭喜您成功抢到【" + stock + "】,得到【"+ point + "】个积分!";
out.println("恭喜您成功抢到【" + stock + "】,得到【"+ point + "】个积分!");
LocalJDBCTemplate.insertData("insert into hd_hotbuy_log (content,mobile) values(?,?)",new Object[]{aa,mobile});
// out.print("ssssssssss");
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(psq!=null){
psq.close();
}
if(rsq!=null){
rsq.close();
}
}
} else {
String sqll = "select * from (select * from hd_hotbuy order by createtime desc ) where rownum<=1 and mobile='"+mobile+"'";
psm = conn.prepareStatement(sqll);
rsm = psm.executeQuery();
while (rsm != null && rsm.next()) {
// SimpleDateFormat sf=new SimpleDateFormat("yyyy-mm-dd hh:mm:ss");
String as1=sf.format(rsm.getTimestamp("createtime").getTime());
java.util.Date as=sf.parse(as1);
// out.println(nowtime);
// out.println("<br/>"+"下面是上一次的时间"+"<br/>");
// out.println(as);
java.util.Date nowtime1=sf.parse(nowtime);
long result = (nowtime1.getTime() - as.getTime())/3600000;
// out.println(result);
if (result<1) {
out.println("对不起,本时段已经抢过了,过一个小时再来吧!");
} else {
try{
LocalJDBCTemplate.insertData("insert into hd_hotbuy (usertime,mobile)values (?,?)",new Object[]{nowtime,mobile});
String sqlm = "select * from hd_hotbuy where random='"+ ran + "'";
psn = conn.prepareStatement(sqlm);
rsn = psn.executeQuery();
String bb="";
String stock="";
String point="";
if (rsn.next()) {
stock = rsn.getString("rank");
point = rsn.getString("point");
out.println("恭喜您成功抢到【" + stock + "】,得到【"
+ point + "】个积分!");
bb="恭喜您成功抢到【" + stock + "】,得到【"+ point + "】个积分!";
LocalJDBCTemplate.insertData("insert into hd_hotbuy_log (content,mobile) values(?,?)",new Object[]{bb,mobile});
// out.print("gggggg");
}
}catch(Exception e){
e.printStackTrace();
}finally{
if(psn!=null){
psn.close();
}
if(rsn!=null){
rsn.close();
}
}
}
}

}
}

} catch (Exception e) {
e.printStackTrace();
}finally{
if(conn!=null){
conn.close();
}
if(rst!=null){
rst.close();
}
if(pst!=null){
rst.close();
}
if(conn!=null){
rst.close();
}

}
%>
<br/>
<%@ include file="../../inc/bottom.jsp" %>
</p>
</card>
</wml>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值