<el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
<el-form-item label="消息名称" prop="noticeTitle">
<el-input v-model="ruleForm.noticeTitle"></el-input>
</el-form-item>
<el-form-item label="消息时间" required>
<el-col :span="11">
<el-form-item prop="date1">
<el-date-picker type="date" placeholder="选择日期" v-model="ruleForm.date1" style="width: 100%;"></el-date-picker>
</el-form-item>
</el-col>
<el-col class="line" :span="2">-</el-col>
<el-col :span="11">
<el-form-item prop="date2">
<el-time-picker placeholder="选择时间" v-model="ruleForm.date2" style="width: 100%;"></el-time-picker>
</el-form-item>
</el-col>
</el-form-item>
</el-form>
效果:
数据:
当你ajax发送数据
date1是年月日,date2是小时分秒,真的没想到是这种格式,我接收的时候傻了都
下面是将date1和2合并成一个时间
Date firstdate = null;
Date seconddate=null;
String dateStr = null;
try {
dateStr = date1.replace("Z", " UTC");//是空格+UTC
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS Z");
firstdate = df.parse(dateStr);
dateStr = date2.replace("Z", " UTC");//是空格+UTC
seconddate = df.parse(dateStr);
System.out.println(seconddate.toString());
Date finalDate=new Date(firstdate.getYear(),firstdate.getMonth(),firstdate.getDate(),seconddate.getHours(),
seconddate.getMinutes(),seconddate.getSeconds());
System.out.println(finalDate.toString());
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
System.out.println(formatter.format(finalDate));
} catch (java.text.ParseException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
核心想法是,将json传过来的字符串转为date,然后用了已经被淘汰get set方法通过构造器将数据一个一个插入date对象,如果有更好的方法请在下面留言。