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
        }
  • 相关阅读:
    洛谷p1056
    __int64
    杭电2057
    4.4清北学堂Day1 主要内容:数论,数学
    递推的一点理解
    高精度减法
    高精度加法
    p1184高手之在一起
    对于rqy今天讲座的一些理解和看法吧
    PHP.21-商品信息管理
  • 原文地址:https://www.cnblogs.com/myz666/p/8446103.html
Copyright © 2011-2022 走看看