package com.zlp.user; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; public class PrintCurrentTime { /** * 将日期按指定格式转换成字符串 * @param date * @param style * @return */ private String dateToString(Date date, String style) { SimpleDateFormat sdf = new SimpleDateFormat(style); if (date != null) { return sdf.format(date); } return null; } public static void main(String[] args) { System.out.println("**********1**********"); String DATE_STYLE_BASIC = "yyyy-MM-dd HH:mm:ss"; System.out.println(new PrintCurrentTime().dateToString(new Date(),DATE_STYLE_BASIC)); System.out.println("**********2**********"); Calendar cal = Calendar.getInstance(); DateFormat df = DateFormat.getDateTimeInstance(DateFormat.SHORT,DateFormat.SHORT); System.out.println(df.format(cal.getTime())); System.out.println("******3*********"); Calendar c = Calendar.getInstance(); System.out.print(c.get(Calendar.YEAR) + "年" + (c.get(Calendar.MONTH) + 1) + "月" + c.get(Calendar.DATE) + "日"); System.out.println(c.get(Calendar.HOUR_OF_DAY) + ":" + c.get(Calendar.MINUTE) + ":" + c.get(Calendar.SECOND)); } } 把 Java util.Date 转成 sql.Date java.util.Date utilDate = new java.util.Date(); java.sql.Date sqlDate = new java.sql.Date(utilDate.getTime());