mhm111

在web页面中当使用如下语句:

<input type="date" name="startTime"/>

提交到servlet中

在servlet页面中:

String startTime = request.getParameter("startTime");

获取到的是字符串类型的时间日期,如下:

2019-06-30

因此需要将字符串类型的时间日期2019-06-03转换为MySQL可以识别的类型存入,如下:

Date startDate=null;

// 注意:SimpleDateFormat构造函数的样式与startTime的样式必须相符,如果不知道的话,可以在servlet页面中输出一下,看一下获取到的时间格式
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");//使用自己的时间格式
// 必须捕获异常

try {
     startDate = simpleDateFormat.parse(startTime);
  } catch (ParseException px) {
     px.printStackTrace();
  }

startDate即为可以直接存入MySQL的数据类型

 

相关文章:

  • 2021-07-07
  • 2021-11-30
  • 2022-01-04
  • 2021-08-05
  • 2021-09-16
  • 2022-01-05
  • 2021-09-26
  • 2022-01-07
猜你喜欢
  • 2021-12-08
  • 2021-07-15
  • 2021-11-19
  • 2021-04-13
  • 2021-11-26
  • 2021-12-12
  • 2021-08-31
相关资源
相似解决方案