/** * Date与String的互转用法,这里需要用到SimpleDateFormat */ Date currentTime = new Date(); SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd"); String dateString = formatter.format(currentTime); Date date = formatter.parse(dateString);
Date与Calendar之间的互转
1 2 3 4 5 6
/** * Date与Calendar之间的互转 */ Calendar cal = Calendar.getInstance(); cal.setTime(new Date()); Date date1 = cal.getTime();