• 博客园logo
  • 会员
  • 众包
  • 新闻
  • 博问
  • 闪存
  • 赞助商
  • HarmonyOS
  • Chat2DB
    • 搜索
      所有博客
    • 搜索
      当前博客
  • 写随笔 我的博客 短消息 简洁模式
    用户头像
    我的博客 我的园子 账号设置 会员中心 简洁模式 ... 退出登录
    注册 登录
蒲公英-----蟹蟹
博客园    首页    新随笔    联系   管理    订阅  订阅
java 获取系统当前时间

   Calendar ca = Calendar.getInstance();
      int year = ca.get(Calendar.YEAR);//获取年份
      int month=ca.get(Calendar.MONTH);//获取月份 
      int day=ca.get(Calendar.DATE);//获取日
      int minute=ca.get(Calendar.MINUTE);//分 
      int hour=ca.get(Calendar.HOUR);//小时 
      int second=ca.get(Calendar.SECOND);//秒
      int WeekOfYear = ca.get(Calendar.DAY_OF_WEEK); //显示今天是一周的第几天

  Date  date=ca.getTime();//获取当前时间(格式需要转换  Fri Jul 29 09:01:50 CST 2016)

 

 

注:Calendar  是抽象工厂

 

 

 

 

方法二:

    SimpleDateFormat myFmt1=new SimpleDateFormat("yyyy-MM-dd  hh:mm:ss");
     Date now=new Date();
      String rq=myFmt1.format(now);

文章只是把遇到的问题,解决的方法记录下来,用于提升自己,如果有更好的方法希望大家留言
posted on 2016-07-29 09:07  蟹蟹xie  阅读(9507)  评论(0)    收藏  举报
刷新页面返回顶部
博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3