美文网首页
关于时分字符串转成当前时间时分

关于时分字符串转成当前时间时分

作者: 么么哒_86ed | 来源:发表于2019-06-26 11:11 被阅读0次

    因业务有对比时间判断,根据当前时分是否执行业务,数据库存的字段是类似于“8:00"的字符串,刚开始没有在意,直接转成date类型 SimpleDateFormat simdate=new SimpleDateFormat("HH:mm");,转完之后年份为1970年,时间校验怎么都是错的,应该要这样转变,才能取到当前的时间的时分

    /**

    * 转换时分

    * @param parmas 时分参数 8:00

    * @return

    */

    public static Date changeDate(String parmas){

    Assert.notNull(parmas,"参数不能为空");

    String trim = parmas.trim();

    Calendar cal=Calendar.getInstance();

    Date now=new Date();

    cal.setTime(now);

    int year =cal.get(Calendar.YEAR);

    int day = cal.get(Calendar.DATE);

    int month = cal.get(Calendar.MONTH) +1;

    SimpleDateFormat simdate=new SimpleDateFormat("yyyy-MM-dd HH:mm");

    try {

    Date changeTime=simdate.parse(year+"-"+month+"-"+day+" "+trim);

    return changeTime;

    }catch (ParseException e) {

    e.printStackTrace();

    }

    return null;

    }

    小功能!让我装下逼

    相关文章

      网友评论

          本文标题:关于时分字符串转成当前时间时分

          本文链接:https://www.haomeiwen.com/subject/vaadfftx.html