Date date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(date);
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
String dateStr = sdf.format(date);
String sql = "select * from ticket where takeDate like '%s'";
sql = String.format(sql, dateStr + "%", 0);
String sql1 = "select * from ticket where isCalled=0 and bus_id='"
+ business.getId() + "'";
String sql2 = "select * from ticket where takeDate like '%s' and bus_id='"
+ business.getId() + "'";
sql2 = String.format(sql2, dateStr + "%", 0);
通过构造函数,实现多态的方法格式化时间类,同样利用重载的方法,利用%s进行传参操作,
String.format(sql2, dateStr + "%", 0);代表向字符串sql2的第一个参数%s 传参。