当前位置: 移动技术网 > IT编程>开发语言>Java > SimpleDateFormat格式化日期

SimpleDateFormat格式化日期

2019年05月08日  | 移动技术网IT编程  | 我要评论
date date=new date();
simpledateformat temp=new simpledateformat("yyyy-mm-dd hh:mm:ss");
string date2=temp.format(date);
date date3=temp.parse(date2);

===================================================================

//这里先获取时间

date date=new date();

 //new一个日期格式,大写hh是24小时制,小写hh是12小时制

simpledateformat temp=new simpledateformat("yyyy-mm-dd hh:mm:ss");

//格式化时间,得到的是string类型
string date2=temp.format(date);

//将string类型的日期date2转换成date型

date date3=temp.parse(date2);

 

 

ps:在向mysql数据库插入日期的时候。字段类型为date,显示出来格式是:yyyy-mm-dd ,字段类型为datetime,显示出来的格式是yyyy-mm-dd hh:mm:ss

值得注意的是:这里大写hh是24小时制,小写hh是12小时制

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网