我是靠谱客的博主 要减肥西装,这篇文章主要介绍JAVA中获取当前系统时间,日期并格式化输出,现在分享给大家,希望可以做个参考。

一.获取当前系统时间和日期并格式化输出:

importjava.util.Date;
importjava.text.SimpleDateFormat;

publicclassNowString{
publicstaticvoidmain(String[]args){
SimpleDateFormatdf=newSimpleDateFormat("yyyy-MM-ddHH:mm:ss");//设置日期格式
System.out.println(df.format(newDate()));//newDate()为获取当前系统时间
}
}

二.在数据库里的日期只以年-月-日的方式输出,可以用下面两种方法:

1、用convert()转化函数:

Stringsqlst="selectconvert(varchar(10),bookDate,126)asconvertBookDatefromroomBookwherebookDatebetween'2007-4-10'and'2007-4-25'";

System.out.println(rs.getString("convertBookDate"));

2、利用SimpleDateFormat类:

先要输入两个java包:

importjava.util.Date;
importjava.text.SimpleDateFormat;

然后:

定义日期格式:SimpleDateFormatsdf=newSimpleDateFormat(yy-MM-dd);

sql语句为:StringsqlStr="selectbookDatefromroomBookwherebookDatebetween'2007-4-10'and'2007-4-25'";

输出:

System.out.println(df.format(rs.getDate("bookDate")));

转载于:https://blog.51cto.com/kimchen/1320468

最后

以上就是要减肥西装最近收集整理的关于JAVA中获取当前系统时间,日期并格式化输出的全部内容,更多相关JAVA中获取当前系统时间内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(71)

评论列表共有 0 条评论

立即
投稿
返回
顶部