免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 4800 | 回复: 2
打印 上一主题 下一主题

新手: java中怎获取当前时间 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2004-08-19 11:48 |只看该作者 |倒序浏览
我想在java中获取当前时间, 怎写

论坛徽章:
0
2 [报告]
发表于 2004-08-19 17:44 |只看该作者

新手: java中怎获取当前时间


  1. /*
  2. * Created on 2004-8-19
  3. *
  4. * TODO To change the template for this generated file go to
  5. * Window - Preferences - Java - Code Style - Code Templates
  6. */

  7. /**
  8. * @author yzq
  9. *
  10. * TODO To change the template for this generated type comment go to
  11. * Window - Preferences - Java - Code Style - Code Templates
  12. */
  13. import java.util.*;

  14. public class GetSysTime
  15. {
  16.         Calendar theCa;
  17.         String nowT;
  18.        
  19.         public void time()
  20.         {
  21.                 theCa = new GregorianCalendar();
  22.                 theCa.setTime(new Date());
  23.                 nowT = " " + (12*theCa.get(Calendar.AM_PM) +  theCa.get(Calendar.HOUR)) + ":" + theCa.get(Calendar.MINUTE) + ":" + theCa.get(Calendar.SECOND);
  24.                 System.out.println("当前时间:"+nowT);
  25.         }
  26.        
  27.         public static void main(String args[])
  28.         {
  29.                 new GetSysTime().time();
  30.         }
  31. }
复制代码

论坛徽章:
0
3 [报告]
发表于 2004-08-21 22:41 |只看该作者

新手: java中怎获取当前时间

public class GetTime
{
    public static void main(String[] args)
    {
        java.sql.Time t = new java.sql.Time(System.currentTimeMillis());
        System.out.println(t);
    }
}
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP