当前位置:Gxlcms > 数据库问题 > util.Date与sql.Date转换

util.Date与sql.Date转换

时间:2021-07-01 10:21:17 帮助过:33人阅读

  SimpleDateFormat f=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");   f.format(stp);   f.format(sTime);   f.format(sqlDate);   f.format(utilDate)   java.sql.Date sqlDate=java.sql.Date.valueOf(" 2005-12-12"技术分享图片);
  utilDate=new java.util.Date(sqlDate.getTime());

  另类取得年月日的方法:

  import java.text.SimpleDateFormat;

  import java.util.*;

  java.util.Date date = new java.util.Date();

  如果希望得到YYYYMMDD的格式SimpleDateFormat

  sy1=new SimpleDateFormat("yyyyMMDD");

  String dateFormat=sy1.format(date);

  如果希望分开得到年,月,日SimpleDateFormat

  sy=new SimpleDateFormat("yyyy");

  SimpleDateFormat sm=new SimpleDateFormat("MM");

  SimpleDateFormat sd=new SimpleDateFormat("dd");

  String syear=sy.format(date);

  String smon=sm.format(date);

  String sday=sd.format(date);
借鉴自:
https://www.cnblogs.com/fengmingyue/p/6048225.html
及

http://blog.csdn.net/qin_zhimou/article/details/55509769

util.Date与sql.Date转换

标签:simple   search   png   strong   stat   date()   时分秒   code   new t   

人气教程排行