zoukankan      html  css  js  c++  java
  • 十五、时间日期类

    1.Date类

    public static void main(String[] args) {
            
            Date d=new Date();
            System.out.println(d);//Tue Feb 13 09:47:32 CST 2018,其中CST表示China Standard Time
    
            SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");//大写M代表month,小写m代表minutes
            System.out.println(sdf.format(d));//2018-00-13 10:00:50
            
            SimpleDateFormat sdf2=new SimpleDateFormat("yy-MM-dd hh:mm:ss");
            System.out.println(sdf2.format(d));//18-02-13 10:00:50
            
            SimpleDateFormat sdf4=new SimpleDateFormat("yyyy-M-d h:m:s");
            System.out.println(sdf4.format(d));//2018-2-13 10:4:31
            
            SimpleDateFormat sdf3=new SimpleDateFormat("yyyy年MM月dd日 hh时mm分ss秒");
            System.out.println(sdf3.format(d));//2018年02月13日 10时03分12秒
        }

    2.Calendar类

    public static void main(String[] args) {
            Calendar c=Calendar.getInstance();//当前时间
            
            int year=c.get(Calendar.YEAR);//获取年
            int month=c.get(Calendar.MONTH)+1;//获取月,0表示一月份
            int day=c.get(Calendar.DAY_OF_MONTH);//获取日
            int hour=c.get(Calendar.HOUR);//获取时
            int minute=c.get(Calendar.MINUTE);//获取分
            int second=c.get(Calendar.SECOND);//获取秒
    
            System.out.println(year+"年 "+month+"月 "+day+"日 "+hour+":"+minute+" "+second);//2018年 2月 13日 10:12 34
            
            System.out.println(c.getTimeInMillis());//表示从1790-1-1 00:00:00到当前时间总共经过的时间的毫秒数,一般用来相减求时间段
            //1518487954629
        }
  • 相关阅读:
    基础抽象代数
    斜堆
    WC2018
    WC2019
    有向图上不相交路径计数
    生成树计数
    Prüfer序列
    反演
    1.1 Linux中的进程 --fork、孤儿进程、僵尸进程、文件共享分析
    Python程序的执行过程 解释型语言和编译型语言
  • 原文地址:https://www.cnblogs.com/myz666/p/8446103.html
Copyright © 2011-2022 走看看