Date in java takes the specific year year

Since the getYear() method is not supported, use the following method

Method 1: Use Calendar 

       Example:

				Date d = rs.getDate("date");//Method 1 is generally Date d = new Date();
				Calendar c = Calendar.getInstance();
				c.setTime(d);
				int y = c.get(Calendar.YEAR);
Method 2: Use SimpleDateFormat

       Example:

				String test=new SimpleDateFormat("yyyy").format(rs.getDate("date"));//Method 2 is generally .format(new Date())

				int y = Integer.parseInt(test);

Attachment: 1. Type conversion method (String to int) https://zhidao.baidu.com/question/290265469.html
        2. Detailed explanation of SimpleDateFormat usage   http://blog.csdn.net/gubaohua/article/details/575488
        3 .Query the data in the data table according to the year in MySqlhttps: //zhidao.baidu.com/question/302206563.html

        4. Array, List, ArrayList usage difference http://www.cnblogs.com/a164266729/p/4561651.html

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325914796&siteId=291194637