將字符串轉化爲時間格式,具體如下:
有這樣一個字符串:“20070911121547”,
轉換成時間格式:2007-09-11 12:15:47
java代碼:
- public class bb {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
-
SimpleDateFormat df = new SimpleDateFormat("yyyyMMddhhmmss");
- String dateString = "20071128175545";
- try {
- Date date = df.parse(dateString);
- System.out.println(df.format(date));
- } catch (Exception ex) {
- System.out.println(ex.getMessage());
- }
- }
- }
try {
Integer yeah = 2016;
Integer moon = 8;
Integer day =15;
LocalDate dateOfBirth = LocalDate.of(yeah, moon, day);
LocalDate ldt = dateOfBirth.plusDays(8);
System.out.println(ldt);
} catch (Exception ex) {
System.out.println(ex.getMessage());
}