...取出一个日期的月和日么?如:xxxx年xx月xx日 得出结果为xx月xx日...

发布网友

我来回答

3个回答

热心网友

public static void main(String[] args) {

try {
String dbURL = "";//这里填入你的数据库的URL地址
String dbUser = "";//这里填入你的数据库的登陆用户名
String dbPsd = "";//这里填入你的数据库的登陆密码
String dbCS = "";//这里填入你的数据库的登陆连接语句
String dbName = "";//这里填入你的数据库表名
String dbSQL = "";//这里填入你的数据库的select语句
String birthStr = "";
Class.forName(dbCS);

Connection conn = DriverManager.getConnection(dbURL + "; DatabaseName= " + dbName, dbUser, dbPsd);

Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery(dbSQL);
while (rs.next()) {
String dbBirthFielName = "";//这里填入你的数据库获取date的那个Field名字
birthStr = rs.getString("dbBirthFielName");

}

rs.close();
stmt.close();
conn.close();
DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

Date birthDate = df.parse(birthStr);
int birthMon = birthDate.getMonth();
int birthDay = birthDate.getDay();
int birthsum = birthMon + birthDay;
Date now = new Date();
int nowMon = now.getMonth();
int nowDay = now.getDay();
int nowhsum = nowMon + nowDay;

if ((birthsum - nowhsum) < 7) {
System.out.println("Happy birthday");
}

} catch (ParseException e) {
// TODO Auto-generated catch block
System.out.println("get parameter is not in conformity with the format ,Pls check the db ");
e.printStackTrace();
} catch (ClassNotFoundException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}
源代码在上面,看看合适不,不合适说声,我改code

热心网友

用字符串的截取方法substring

热心网友

转换为Date格式的,在获取月份和天数

声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com