zoukankan      html  css  js  c++  java
  • java获取当前时间

    /////////////////获取时间方法一//////////////////////////////
          java.util.Date uDate=new java.util.Date();
          System.out.println("uDate: "+uDate);
         java.sql.Date sDate=new java.sql.Date(uDate.getTime());
          System.out.println("sDate: "+sDate);
        /////////////获取时间方法二/////////////////////////////
          String time=null;
          SimpleDateFormat df=new SimpleDateFormat("yyyy-MM-dd HH:MM:ss");//设置日期格式
          time=df.format(new Date());// new Date()为获取当前系统时间
          System.out.println("strDate: "+time);
        //生成时间实例: 2014-10-11 19:10:09
        ///////////////////////获取时间方法三////////////////////////////
          DateFormat d2 = DateFormat.getDateTimeInstance(); 
          String time = d2.format(new Date());
    
    
    ///////////////查询时间格式方法集合//////////////////////////////////////////////////////////////
        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("用DateFormat.getDateTimeInstance(DateFormat.MEDIUM,DateFormat.MEDIUM)格式化时间后为:" + str8);
           
  • 相关阅读:
    多层次子查询的sql执行顺序的问题
    RestTemplate不落地中转文件
    Gitbook从安装到使用【转】
    Linux离线安装依赖包技巧
    CentOS7 配置环境变量断开ssh后失效
    分页查询排序问题
    地图坐标的转换
    FeatureLayer图层的属性查询方式(query的使用方法)
    使用LayerView.effect进行点的高亮显示
    DQL + 排序
  • 原文地址:https://www.cnblogs.com/zhang-cb/p/6112600.html
Copyright © 2011-2022 走看看