java修改时间_java怎么根据时间改变学习?

//如果你表里没有时间则会报空指针

public Body upTimeCourse(Stucourse stucourse1, String stuId) {

Stucourse sc = new Stucourse();

EntityWrapper ews = new EntityWrapper<>();

ews.eq("stu_id", stuId);

List list = sc.selectList(ews);

List lists = new ArrayList<>();

if (list.size() == 0) {

return Body.newInstance(404, "找不到此学生");

}

for (Stucourse stucourse : list) {

// ***************取出该对象的开始结束时间

String starttime = stucourse.getCourseStarttime();

String endtime = stucourse.getCourseEndtime();

StringBuffer sb = new StringBuffer();

sb.append(starttime.substring(0, 4));

sb.append(starttime.substring(5, 7));

sb.append(starttime.substring(8, 10));

sb.append(starttime.substring(11, 13));

sb.append(starttime.substring(14, 16));

long stime = Long.parseLong(sb.toString());

System.out.println("课程开始时间:" + stime);

// 将结束时间转换成可计算类型Long

StringBuffer ssb = new StringBuffer();

ssb.append(endtime.substring(0, 4));

ssb.append(endtime.substring(5, 7));

ssb.append(endtime.substring(8, 10));

ssb.append(endtime.substring(11, 13));

ssb.append(endtime.substring(14, 16));

long etime = Long.parseLong(ssb.toString());

System.out.println("课程结束时间:" + etime);

// 当前时间

StringBuffer dqsb = new StringBuffer();

SimpleDateFormat nian = new SimpleDateFormat("yyyy");// 设置日期格式

dqsb.append(nian.format(new Date()));

SimpleDateFormat yue = new SimpleDateFormat("MM");

dqsb.append(yue.format(new Date()));

SimpleDateFormat ri = new SimpleDateFormat("dd");

dqsb.append(ri.format(new Date()));

SimpleDateFormat shi = new SimpleDateFormat("HH");

dqsb.append(shi.format(new Date()));

SimpleDateFormat fen = new SimpleDateFormat("mm");

dqsb.append(fen.format(new Date()));

long nowtime = Long.parseLong(dqsb.toString());

System.out.println("当前系统时间:" + nowtime);

// 开始判断课程状态 用到三个变量 nowtime 、stime、etime

if (nowtime < stime) {

stucourse.setFanhuijieguo("课程未开始");

} else if (nowtime > stime && nowtime < etime) {

stucourse.setFanhuijieguo("课程进行中");

} else if (nowtime > etime) {

stucourse.setFanhuijieguo("课程已结束");

}

lists.add(stucourse);

}

if (lists.size() > 0) {

return Body.newInstance(lists);

}

return Body.newInstance(404, "好像出了点小问题,等会再试一下吧");

}

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值