前端后端日期格式的转换

时间格式截取

public static void main(String[] args) {
    String a = new String("2019-09-18T07:27:05.000+0000");
    SimpleDateFormat sim = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    String b = a.substring(0,19).replace("T"," ");
    System.out.println("========"+b);

}

 

web到后台Java时data日期类型的转化,java到数据库data日期格式转化

 

前台到java:

实体类中用@DateTimeFormat这样即是传过来是空的字符串也可以转,要和前面传过来的格式一致

 

@XmlElement(name = "BeginDate")

@DateTimeFormat(pattern = "yyyyMMdd")

private Date beginDate;

// 结束日期

@XmlElement(name = "EndDate")

@DateTimeFormat(pattern = "yyyyMMdd")

private Date endDate;

 

 不需要管前面传过来的格式

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

String str=SFDate.format(entity.getTranDate());//entity.getTranDate();

 

 

java到数据库:

java到数据库用to_date('2017-04-07 00:00:00' , 'YYYY-MM-DD HH24:MI:SS');转化

 

String str= "2017-04-07 00:00:00";

List tb= jdbcTemplate.query("select * from TB_SETT_INMONEY t where t.acct_date=to_date (? , 'YYYY-MM-DD HH24:MI:SS' )", new Object[]{str},new RowMapper(){

 

@Override

public Object mapRow(ResultSet rs, int rowNum) throws SQLException {

// TODO Auto-generated method stub

TbSettInmoney tb= new TbSettInmoney();

tb.setSupAcctId(rs.getString("SUP_ACCT_ID"));

//tb.setCustFlag(rs.getInt("CUST_FLAG"));

//tb.setTranDate(rs.getDate("TRAN_DATE"));

return tb;

}

 

});

//jdbcTemplate.queryForList("select * from tb_sett_fund t where t.sup_acct_id=?", new Object[]{str}, new TbSettFund());

System.out.println(tb.size());

你可能感兴趣的:(前端后端日期格式的转换)