zoukankan      html  css  js  c++  java
  • 常用类_日期类

    日期时间类

        计算机时间戳是指距离历元(1970-01-0零时零分零秒)的时间间隔(ms)

        特点:

          @注意:毫秒为单位

          @用long类型存储。

          @格林尼治俗称(GMT),是一个标准时间,用于全球时间的标准化。各国通过时区偏移来定义各国的标准时间。例如 中国的标准时 =  UTC+08:00  日本的标准时 = UTC+09:00

        Date  类

        类 Date 表示 特定的瞬间,精确到毫秒

        特性:

          @当创建一个Date对象是,表示当前时间

          @根据当地时区创建当前时间

        日期时间的格式化

        //使用指定模式格式化
        Date  date = new Date();
        SimpleDateFormat sd= new SimpleDateFormat("yyyy年MM月dd日");
        String datestring = sd.format(sd);
        //修改模式
        sd.applyPattern("yyyy:MM:dd");

        把指定的格式字符串解析成Date

                Date D= new Date();
                long k= D.getTime();
                System.out.println(k);
                //时间格式
                SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy年MM月dd日");
                String  aString = simpleDateFormat.format(D);
                System.out.println(aString);
                //重新创建一个时间对象,时间格式为上一个时间格式化
                Date date = simpleDateFormat.parse(aString);
                System.out.println(date);

        Calendar 类

            Calendar取代Date获取单独的年,月,日,时,分,秒

            Calendar是日历类,本质上内部拥有一个属性long time .并提供set 和 get 方法用于设置或者访问这些字段

          

         public static void main(String[] args) {
            Calendar dCalendar  =  Calendar.getInstance();
            //获取当天的日期
            System.out.println(dCalendar.get(Calendar.DATE));
            //获取年
            System.out.println(dCalendar.get(Calendar.YEAR));
            //
            System.out.println(dCalendar.get(Calendar.MARCH));
        }
  • 相关阅读:
    读书笔记--SQL必知必会21--使用游标
    读书笔记--SQL必知必会20--管理事务处理
    读书笔记--SQL必知必会19--存储过程
    读书笔记--SQL必知必会18--视图
    PopupWindow
    android shape的使用
    带删除小图标的EditText
    Android点击EditText文本框之外任何地方隐藏键盘的解决办法
    Android px、dp、sp之间相互转换
    android edittext不弹出软键盘
  • 原文地址:https://www.cnblogs.com/dedema/p/10798146.html
Copyright © 2011-2022 走看看