在java中给数据库添加时间,怎么把字符串类型转换成时间类型?怎么往数据库中添加?

如题所述

第1个回答  推荐于2021-01-07
这个是字符串转化成时间

String brithday=new String("1991-02-02");
SimpleDateFormat a=new SimpleDateFormat("yyyy-MM-dd");
Date b=a.parse(brithday);
System.out.println("将字符串转化为时间是"+b);
这个是时间转化成字符串
SimpleDateFormat sdf = new SimpleDateFormat( "yyyyMMDDHHMMSSmmm ");
System.out.println(sdf.format(new Date()));本回答被提问者和网友采纳
第2个回答  2012-12-15
有根据字符串创建时间类型对象的方法,比如 DateFormat.parse(String s)
第3个回答  2012-12-15
我都把数据库中表示时间的字段用字符类型表示,不用时间类型
第4个回答  2012-12-15
to_char(属性,"日期格式")
第5个回答  推荐于2018-04-21
Date date =new SimpleDateformat("yyyy-mm-dd hh:mm:ss").parse(dateString);
相似回答