首页 / JAVA / JAVA中获取系统时间
JAVA中获取系统时间
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了JAVA中获取系统时间,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含8740字,纯文字阅读大概需要13分钟。
内容图文
![JAVA中获取系统时间](/upload/InfoBanner/zyjiaocheng/1071/6debe5fa1a0f41cc907730c7a829f050.jpg)
import java.text.SimpleDateFormat; <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>public class NowString {
public static void main(String[] args) {
SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
System.out.println(df.format(new Date()));// new Date()为获取当前系统时间
}
} <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>二. 在数据库里的日期只以年-月-日的方式输出,可以用下面两种方法: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>1、用convert()转化函数: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>String sqlst = "select convert(varchar(10),bookDate,126) as convertBookDate from roomBook where bookDate between ‘2007-4-10‘ and ‘2007-4-25‘"; <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>System.out.println(rs.getString("convertBookDate")); <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>2、利用SimpleDateFormat类: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>先要输入两个java包: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>import java.util.Date;
import java.text.SimpleDateFormat; <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>然后: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>定义日期格式:SimpleDateFormat sdf = new SimpleDateFormat(yy-MM-dd); <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>sql语句为:String sqlStr = "select bookDate from roomBook where bookDate between ‘2007-4-10‘ and ‘2007-4-25‘"; <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>输出: <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>System.out.println(df.format(rs.getDate("bookDate"))); <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘> <P style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 10px auto; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘>************************************************************ <DIV style=‘font: 14px/21px verdana, "ms song", Arial, Helvetica, sans-serif; margin: 0px; padding: 0px; text-align: left; color: rgb(57, 57, 57); text-transform: none; text-indent: 0px; letter-spacing: normal; word-spacing: 0px; white-space: normal; orphans: 2; widows: 2; font-size-adjust: none; font-stretch: normal; background-color: rgb(250, 247, 239); -webkit-text-stroke-width: 0px; -webkit-text-size-adjust: auto;‘ class="tit">java中获取当前日期和时间的方法
内容总结
以上是互联网集市为您收集整理的JAVA中获取系统时间全部内容,希望文章能够帮你解决JAVA中获取系统时间所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。