JAVA获取当前时间的方法.doc

  1. 1、本文档共4页,可阅读全部内容。
  2. 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
JAVA获取当前时间的方法

Java中获得当前时间的方法 2008年06月16日 星期一 下午 10:06 有两种方法: 方法一:用java.util.Date类来实现,并结合java.text.DateFormat类来实现时间的格式化,看下面代码: import java.util.*; import java.text.*; //以下默认时间日期显示方式都是汉语语言方式 //一般语言就默认汉语就可以了,时间日期的格式默认为MEDIUM风格,比如:2008-6-16 20:54:53 //以下显示的日期时间都是再Date类的基础上的来的,还可以利用Calendar类来实现见类TestDate2.java public class TestDate public static void main String[] args Date now new Date ; Calendar cal Calendar.getInstance ; DateFormat d1 DateFormat.getDateInstance ; //默认语言(汉语)下的默认风格(MEDIUM风格,比如:2008-6-16 20:54:53) String str1 d1.format now ; DateFormat d2 DateFormat.getDateTimeInstance ; String str2 d2.format now ; DateFormat d3 DateFormat.getTimeInstance ; String str3 d3.format now ; DateFormat d4 DateFormat.getInstance ; //使用SHORT风格显示日期和时间 String str4 d4.format now ; DateFormat d5 DateFormat.getDateTimeInstance DateFormat.FULL,DateFormat.FULL ; //显示日期,周,时间(精确到秒) String str5 d5.format now ; DateFormat d6 DateFormat.getDateTimeInstance DateFormat.LONG,DateFormat.LONG ; //显示日期。时间(精确到秒) String str6 d6.format now ; DateFormat d7 DateFormat.getDateTimeInstance DateFormat.SHORT,DateFormat.SHORT ; //显示日期,时间(精确到分) String str7 d7.format now ; DateFormat d8 DateFormat.getDateTimeInstance DateFormat.MEDIUM,DateFormat.MEDIUM ; //显示日期,时间(精确到分) String str8 d8.format now ;//与SHORT风格相比,这种方式最好用 System.out.println 用Date方式显示时间: + now ;//此方法显示的结果和Calendar.getInstance .getTime 一样 System.out.println 用DateFormat.getDateInstance 格式化时间后为: + str1 ; System.out.println 用DateFormat.getDateTimeInstance 格式化时间后为: + str2 ; System.out.println 用DateFormat.getTimeInstance 格式化时间后为: + str3 ; System.out.println 用DateFormat.getInstance 格式化时间后为: + str4 ; System.out.println 用DateFormat.getDateTimeInstance DateFormat.FULL,DateFormat.FULL 格式化时间后为: + str5 ; System.out.println 用DateFormat.getDateTimeInstance DateFormat.LONG,DateFormat.LONG 格式化时间后为: + str6 ; System.out.println 用DateFormat.getDateTimeInstance DateFormat.SHORT,DateFormat.SHORT 格式化时间后为: + str7 ; System.out.println 用D

文档评论(0)

tiangou + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档