当前位置: 技术问答>java相关
简单问题,如何把字符串格式的20021212转化为日期型的2002-12-12?
来源: 互联网 发布时间:2017-03-21
本文导语: 简单问题,如何把字符串格式的20021212转化为日期型的2002-12-12? | 给个例子给你: String a = "20021211"; int year = Integer.parseInt(a.substring(0,4)); int month = Integer.parseInt(a.substring(4,6...
简单问题,如何把字符串格式的20021212转化为日期型的2002-12-12?
|
给个例子给你:
String a = "20021211";
int year = Integer.parseInt(a.substring(0,4));
int month = Integer.parseInt(a.substring(4,6));
int day = Integer.parseInt(a.substring(6,8));
System.out.println("year:"+year+"month:"+month+"day:"+day);
java.sql.Date d = new java.sql.Date(year-1900,month-1,day);
System.out.println(d.toString());
String a = "20021211";
int year = Integer.parseInt(a.substring(0,4));
int month = Integer.parseInt(a.substring(4,6));
int day = Integer.parseInt(a.substring(6,8));
System.out.println("year:"+year+"month:"+month+"day:"+day);
java.sql.Date d = new java.sql.Date(year-1900,month-1,day);
System.out.println(d.toString());